Developer forum

Forum » Templates » Rendering tags in Loop header and footer

Rendering tags in Loop header and footer


Reply

How do I render template tags in the Header section of the loop?

 

In the following example I would like to render the product id into the image id in the header

 

 <!--@LoopStart(Pricelist)-->

<!--@HeaderStart--> <img id="Img_<!--@Ecom:Product.ID-->" src="discount.gif"/>

 

<table cellpadding="2" cellspacing="0" border="0" width="170px;">

 

<!--@HeaderEnd-->

 

<tr><td align="left"><!--@Pricelist:Quantity--></td><td align="right"><!--@Pricelist:Price--></td></tr>

 

<!--@FooterStart-->

 

</table>

 

<!--@FooterEnd-->

 

<!--@LoopEnd(Pricelist)-->

 

 

 

 


Replies

 
Nicolai Høeg Pedersen
Reply
thl@dk.columbusit.com wrote:

How do I render template tags in the Header section of the loop?

 

In the following example I would like to render the product id into the image id in the header

 

 <!--@LoopStart(Pricelist)-->

<!--@HeaderStart--> <img id="Img_<!--@Ecom:Product.ID-->" src="discount.gif"/> <table cellpadding="2" cellspacing="0" border="0" width="170px;">

 

<!--@HeaderEnd-->

 

<tr><td align="left"><!--@Pricelist:Quantity--></td><td align="right"><!--@Pricelist:Price--></td></tr>

 

<!--@FooterStart-->

 

</table>

 

<!--@FooterEnd-->

 

<!--@LoopEnd(Pricelist)-->

 

 

 

 

 

 

A loop has its own context and does not share any template tags with the rest of the template. Therfore you can not use the templatetags from the rest of the template inside the loop - and headers as well.
 

 

So you will have to be "creative" to solve this issue...

 
Reply
np wrote:
thl@dk.columbusit.com wrote:

How do I render template tags in the Header section of the loop?

 

In the following example I would like to render the product id into the image id in the header

 

 <!--@LoopStart(Pricelist)-->

<!--@HeaderStart--> <img id="Img_<!--@Ecom:Product.ID-->" src="discount.gif"/> <table cellpadding="2" cellspacing="0" border="0" width="170px;"> <!--@HeaderEnd-->

 

<tr><td align="left"><!--@Pricelist:Quantity--></td><td align="right"><!--@Pricelist:Price--></td></tr>

 

<!--@FooterStart-->

 

</table>

 

<!--@FooterEnd-->

 

<!--@LoopEnd(Pricelist)-->

 

 

 

 

 

 

 

 

A loop has its own context and does not share any template tags with the rest of the template. Therfore you can not use the templatetags from the rest of the template inside the loop - and headers as well.
 

 

So you will have to be "creative" to solve this issue...

 

 

The Ecom:Product.ID tag in the Header section was a bad exampel. I should have been a "custom" tag like the Pricelist:Quantity tag.

 

In ny code i render the Pricelist:Quantity and Pricelist:Price tags for each element in the loop.  Se the following exampel.
 

Dynamicweb.Templatev2.

Template objPricelistLoopTemplate = new Dynamicweb.Templatev2.Template();"Pricelist");

 

{

foreach (Price objPrice in objPriceCollection)

objPricelistLoopTemplate.SetTag(

objPricelistLoopTemplate.SetTag(

objPricelistLoopTemplate.CommitLoop();

}

"Pricelist:Quantity",objPrice.Quantity + " stk.");"Pricelist:Price", String.Format("{0:C}", objPrice.PriceWithDiscount));

 

 

How do I in this code render a templatetag in the Header section of the loop?

objPricelistLoopTemplate = parmTemplate.GetLoop(

 
Nicolai Høeg Pedersen
Reply

Because of the way loop header works its just not possible...

 

When GetLoop is called, the template file is split up in 2 (or more) and separated in different objects. The header and footer are stored out of these objects until the output is called. Tags can not be set...

 

But you can do something like this - ugly but works...:

 

 Dim t As New Templatev2.Template("some/template.html")
   Dim t2 As Templatev2.Template = t.GetLoop("myLoop")
   For i As Integer = 0 To 5
    t2.SetTag("aNumber", i)
    t2.CommitLoop()
   Next
   Dim t3 As New Templatev2.Template
   t3.Html = t.Output
   t3.SetTag("SomeSemiGlobalTag", "Hello...")
   Return t3.Output

 

 
Reply
np wrote:

Because of the way loop header works its just not possible...

 

When GetLoop is called, the template file is split up in 2 (or more) and separated in different objects. The header and footer are stored out of these objects until the output is called. Tags can not be set...

 

But you can do something like this - ugly but works...:

 

 Dim t As New Templatev2.Template("some/template.html")
   Dim t2 As Templatev2.Template = t.GetLoop("myLoop")
   For i As Integer = 0 To 5
    t2.SetTag("aNumber", i)
    t2.CommitLoop()
   Next
   Dim t3 As New Templatev2.Template
   t3.Html = t.Output
   t3.SetTag("SomeSemiGlobalTag", "Hello...")
   Return t3.Output

 


 

In a future release a GetLoopHeader and GetLoopFooter methods would be nice features

 

You must be logged in to post in the forum