Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Loop name by GetString does not work

Loop name by GetString does not work

Lars Larsen
Lars Larsen
Reply

Hi

I have a paragraph template with this code:

var loopname = "Item." + GetString("Item.ItemTypeName.Value") + ".Options";
foreach (var option in GetLoop(loopname))

Now the loop doesn't contain any items. But if I use this code:

var loopname = "Item.Ruling.Options";                 // 'Ruling' is the itemtype name
foreach (var option in GetLoop(loopname))

The loop contains items as expected. But why does the first piece of code not work? The strange thing is, that if a TemplateTags() method call exists in the template then the first piece of code works! Is this by design or what?

Running on DW9.1

 


Replies

 
Nicolai Pedersen
Reply

Hi Lars

What do you get if you just print out the GetString("Item.ItemTypeName.Value") value?

What do you see if you add @TemplateTags() in the template to get a list of all the tags and their values?

And what do you get if you print out @loopname to the template?

 
Gaëtan Di Caro
Reply

I've had a similar problem last year and it turned out that if the template tag you want to access isn't spelled out explicitly in the template, Dynamicweb won't take it into account. I wanted to loop on tags called Image1 to 10. For my code to work I had to put a comment in my template with all the different names, so that Dynamicweb knows i'm supposed to use them here.

Don't know if this had changed since.

 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

I have simplified my code a bit, so now it looks like this:

var loopname = "Rulings";
foreach (var option in GetLoop("Item." + loopname + ".Options"))
{
       <text>In loop<br/></text>
}

Now when running this code there are no items in the loop. But if I add @TemplateTags() like this:

var loopname = "Rulings";
@TemplateTags()
foreach (var option in GetLoop("Item." + loopname + ".Options"))
{
       <text>In loop<br/></text>
}

the loop contains items. The same happens if the code looks like this:

var loopname = "Rulings";
//foreach (var option in GetLoop("Item.Rulings.Options"))
foreach (var option in GetLoop("Item." + loopname + ".Options"))
{
       <text>In loop<br/></text>
}

TemplateTags() output this:

Global.PageId System.Int32 3059
Global.PagingPosition System.Int32 1
Global.ParagraphId System.Int32 3074
Item.Field.First System.Boolean False
Item.Field.Last System.Boolean True
Item.Heading System.String Link liste
Item.Heading.IsRequired System.Boolean False
Item.Heading.Name System.String Overskrift
Item.Heading.SystemName System.String Heading
Item.Heading.Type System.String Text
Item.Heading.Value System.String Link liste
Item.Id System.String 1
Item.Id.IsRequired System.Boolean False
Item.Id.Name System.String Id
Item.Id.SystemName System.String Id
Item.Id.Type System.String Text
Item.Id.Value System.String 1
Item.ItemInstanceType System.String  
Item.ItemInstanceType.IsRequired System.Boolean False
Item.ItemInstanceType.Name System.String ItemInstanceType
Item.ItemInstanceType.SystemName System.String ItemInstanceType
Item.ItemInstanceType.Type System.String Text
Item.ItemInstanceType.Value System.String  
Item.ItemTypeName System.String Ruling
Item.ItemTypeName.IsRequired System.Boolean False
Item.ItemTypeName.Name System.String Indholdstype
Item.ItemTypeName.SystemName System.String ItemTypeName
Item.ItemTypeName.Type System.String Radio button list
Item.ItemTypeName.Value System.String Ruling
Item.ParagraphHeader System.String Link liste
Item.ParagraphHeader.IsRequired System.Boolean False
Item.ParagraphHeader.Name System.String ParagraphHeader
Item.ParagraphHeader.SystemName System.String ParagraphHeader
Item.ParagraphHeader.Type System.String Text
Item.ParagraphHeader.Value System.String Link liste
Item.ParagraphName System.String Link liste
Item.Rulings System.String  
Item.Rulings.IsRequired System.Boolean False
Item.Rulings.Name System.String Afgørelser
Item.Rulings.SystemName System.String Rulings
Item.Rulings.Type System.String Checkbox list
Item.Rulings.Value System.String  
Item.Sort System.String 1
Item.Sort.IsRequired System.Boolean False
Item.Sort.Name System.String Sort
Item.Sort.SystemName System.String Sort
Item.Sort.Type System.String Text
Item.Sort.Value System.String 1
Item.SystemName System.String LinkList
Item.Text System.String  
Item.Text.IsRequired System.Boolean False
Item.Text.Name System.String Tekst
Item.Text.SystemName System.String Text
Item.Text.Type System.String Rich text
Item.Text.Value System.String  
ParagraphContainer System.String content
ParagraphContainerCount System.Int32 2
ParagraphContainerIsFirst System.Boolean True
ParagraphContainerIsLast System.Boolean False
ParagraphContainerSort System.Int32 1
ParagraphGlobalID System.Int32 0
ParagraphHeader System.String Link liste
ParagraphID System.Int32 3074
ParagraphImage System.String  
ParagraphImageClean    
ParagraphImageHAlign System.String left
ParagraphImageHeight System.Int32 0
ParagraphImageLinkAlt System.String  
ParagraphImageLinkClean System.String  
ParagraphImageLinkTarget System.String  
ParagraphImageVAlign System.String top
ParagraphImageWidth System.Int32 0
ParagraphModule System.String  
ParagraphPageID System.Int32 3059
ParagraphText System.String  
Setting.items-allowed System.String Article, TwoColLinkList, LinkList
Template:BaseUrl System.String /Files/Templates/Designs/Boligjura/Paragraph/
Template:DesignBaseUrl System.String /Files/Templates/Designs/Boligjura/
Loops  
Item.Groups  
Item.Fields  
Item.ItemTypeName.Options  
Item.Rulings.Options
Global.PageId System.Int32 3059
Global.PagingPosition System.Int32 1
Global.ParagraphId System.Int32 3074
Item.Field.First System.Boolean False
Item.Field.Last System.Boolean True
Item.Heading System.String Link liste
Item.Heading.IsRequired System.Boolean False
Item.Heading.Name System.String Overskrift
Item.Heading.SystemName System.String Heading
Item.Heading.Type System.String Text
Item.Heading.Value System.String Link liste
Item.Id System.String 1
Item.Id.IsRequired System.Boolean False
Item.Id.Name System.String Id
Item.Id.SystemName System.String Id
Item.Id.Type System.String Text
Item.Id.Value System.String 1
Item.ItemInstanceType System.String  
Item.ItemInstanceType.IsRequired System.Boolean False
Item.ItemInstanceType.Name System.String ItemInstanceType
Item.ItemInstanceType.SystemName System.String ItemInstanceType
Item.ItemInstanceType.Type System.String Text
Item.ItemInstanceType.Value System.String  
Item.ItemTypeName System.String Ruling
Item.ItemTypeName.IsRequired System.Boolean False
Item.ItemTypeName.Name System.String Indholdstype
Item.ItemTypeName.SystemName System.String ItemTypeName
Item.ItemTypeName.Type System.String Radio button list
Item.ItemTypeName.Value System.String Ruling
Item.ParagraphHeader System.String Link liste
Item.ParagraphHeader.IsRequired System.Boolean False
Item.ParagraphHeader.Name System.String ParagraphHeader
Item.ParagraphHeader.SystemName System.String ParagraphHeader
Item.ParagraphHeader.Type System.String Text
Item.ParagraphHeader.Value System.String Link liste
Item.ParagraphName System.String Link liste
Item.Rulings System.String  
Item.Rulings.IsRequired System.Boolean False
Item.Rulings.Name System.String Afgørelser
Item.Rulings.SystemName System.String Rulings
Item.Rulings.Type System.String Checkbox list
Item.Rulings.Value System.String  
Item.Sort System.String 1
Item.Sort.IsRequired System.Boolean False
Item.Sort.Name System.String Sort
Item.Sort.SystemName System.String Sort
Item.Sort.Type System.String Text
Item.Sort.Value System.String 1
Item.SystemName System.String LinkList
Item.Text System.String  
Item.Text.IsRequired System.Boolean False
Item.Text.Name System.String Tekst
Item.Text.SystemName System.String Text
Item.Text.Type System.String Rich text
Item.Text.Value System.String  
ParagraphContainer System.String content
ParagraphContainerCount System.Int32 2
ParagraphContainerIsFirst System.Boolean True
ParagraphContainerIsLast System.Boolean False
ParagraphContainerSort System.Int32 1
ParagraphGlobalID System.Int32 0
ParagraphHeader System.String Link liste
ParagraphID System.Int32 3074
ParagraphImage System.String  
ParagraphImageClean    
ParagraphImageHAlign System.String left
ParagraphImageHeight System.Int32 0
ParagraphImageLinkAlt System.String  
ParagraphImageLinkClean System.String  
ParagraphImageLinkTarget System.String  
ParagraphImageVAlign System.String top
ParagraphImageWidth System.Int32 0
ParagraphModule System.String  
ParagraphPageID System.Int32 3059
ParagraphText System.String  
Setting.items-allowed System.String Article, TwoColLinkList, LinkList
Template:BaseUrl System.String /Files/Templates/Designs/Boligjura/Paragraph/
Template:DesignBaseUrl System.String /Files/Templates/Designs/Boligjura/
Loops  
Item.Groups  
Item.Fields  
Item.ItemTypeName.Options  
Item.Rulings.Options
 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Lars

That is what Gaëtan explains. It is because the rendering engine looks at the template content to figure out which loops to render - so if the loopname is not explicitly in the template, we do not render the values to save performance. When you add @TemplateTags() that check is disabled and you can render it...

So no great way to get the loops in there dynamically... Only by including the full names.

Votes for this answer: 1
 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

Ok it makes sence to save performance when the loop is not explicitly in the template. Good to know the reason why it teased me. But as Gaëtan mentioned if you just add a comment with GetLoop([loopname]) the rendering engine will render the loop values. That will be my work around, because I really want to have the loop name in a variable in order to have less code in my template. 

 

You must be logged in to post in the forum