Developer forum

Forum » Development » Add a Tag to each loop element after the CommitLoop()

Add a Tag to each loop element after the CommitLoop()

Diogo Lino
Reply
Hi,

Imagine that I have created normally a loop (variable "loopTemplate") with 3 elements in a template (variable "template"), and the result can be shown like this:
<!--@LoopStart(Person.DivisionsList)-->
	Counter: <!--@Person.DivisionsList.LoopCounter--> <br />
	Title: <!--@Person.DivisionsList.Title--> <br />
	Meters: <!--@Person.DivisionsList.Meters--> <br /><br />
<!--@LoopEnd(Person.DivisionsList)-->
Counter: 1
Title: Room 1
Meters: 12

Counter: 2
Title: Kitchen
Meters: 17

Counter: 3
Title: Room 2
Meters: 25

How can I add a Tag to each element of the loop after the foreach() cicle and "loopTemplate.CommitLoop()" proccess??
For example, to add a "Person.DivisionsList.Color" tag to each element of the loop...

I've tried an approach like this...
Loop loop = template.Loops.GetLoopByName("Person.DivisionsList");
loop.Template.SetTag("Person.DivisionsList.Color", "Red");
loop.Template.SetTag("Person.DivisionsList.Color", "Blue");
loop.Template.SetTag("Person.DivisionsList.Color", "White");
loop.Template.CommitLoop();

...but it adds a 4th loop element with only the last tag (the color white).

I need to navigate the loop and add a tag to each element, but the "loop.Template.Tags" property is empty to create a foreach, for example.

Any ideas?

Thanks,
Diogo


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
I am not 100% sure but I don't think you can do that. You may be able to look at the data in the template object and figure out a way to change the data afterwards, but I think that'll be pretty messy.

Why don't you add the Color tag when creating the loop? If you only have the color information available after you create the loop, postpone loading the loop (by storing the data in a Dictionary for example), and then render all tags at once when you have the Color information available.

Cheers,

Imar
 
Diogo Lino
Reply
I have a function that receives a Template and an Object, and it creates all the tags and loops for its properties and content, so the template object has all the loops and tags created after that.

I use it to create tags from an object received from a webservice, so I can't change the object before, and a simple way I thought was to navigate the Template object properties after being changed by this function, but I don't find the necessary information in the Template object at first sight.

Thanks,
Diogo

 

You must be logged in to post in the forum