Developer forum

Forum » Development » Loop tags in CustomModule

Loop tags in CustomModule


Reply

I've seen at blogpost or forum thread about this earlier, but i can't seem to find it anywhere now, so i'll just ask the question again.

 

I've made at custom module where i need to display the content of a User table in the frontend. I want to create a custom looptag, so i can easily design how my userlist will appear on the page.

 

But how do i do it?

 

i need a tag like this <!--@loopstart(PersonList)--><!--@loopend(PersonList)-->

and the ability to define my own tags within the loop.

 

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

Dim myTemplate As New Templatev2.Template("some/Some.html")
   Dim myLoop As Templatev2.Template = myTemplate.GetLoop("PersonList")
   Using dr As IDataReader = Database.getDataReader("select * from persons")
    Do While dr.Read
     myLoop.SetTag("name", Base.ChkString(dr.Item("name")))
     myLoop.SetTag("email", Base.ChkString(dr.Item("email")))
     'Or simply:
     myLoop.SetTags(dr)
     myLoop.CommitLoop()
    Loop
   End Using
   Return myTemplate.Output

 
Reply

I addapted your example til C# And edited a bit, but i can seem to get the loop going.

My code looks like this:

 

----

 

Dynamicweb.Templatev2.Template ResultTemplate = new Dynamicweb.Templatev2.Template( "ADSearch/" + Properties.get_Value( "ResultTemplate" ) );

 

User user = new User();
Dynamicweb.Templatev2.Template SearchLoop = ResultTemplate.GetLoop( "SearchResult" );
 

List<User> AllUsers = user.GetUsersFromSearch( "Martin"); // This object containes 5 users.
foreach ( User U in AllUsers ) {
 SearchLoop.SetTag("cm.Name", U.FirstName + " " + U.Initials + " " + U.LastName);
 SearchLoop.SetTag("cm.Email", U.Email);
 SearchLoop.SetTag("cm.Department", U.Department);
 SearchLoop.SetTag("cm.Phone", U.Phone);
 SearchLoop.SetTag("cm.Country", U.Country);
 SearchLoop.SetTag("cm.Local", U.LocalNumber);

}    

                   

ResultTemplate.SetTag( "cm.ResultCount", AllUsers.Count.ToString() );
ResultTemplate.SetTag( "cm.SearchWord", SearchWord );
ResultTemplate.SetTag( "cm.PostBack", PostBack.ToString() );

 

Return ResultTemplate.Output;

  

----

 

In my template i use the following templatetags to get me loop, but nothing is returned:

 

<!--@LoopStart(SearchResult)-->
<!--@DwTemplateTags-->
<!--@LoopEnd(SearchResult)-->

 

My "cm.ResultCount" and "cm.SearchWord" are returned just fine. did i do something wrong?

 

 

 
Reply

You forgot .CommitLoop in your code. Otherwice it looks fine.

 
Reply

Yeah, i just noticed it my self.

Works great now.

 

thanks.

 

 

You must be logged in to post in the forum