Developer forum

Forum » Templates » RE: ItemList iteration

RE: ItemList iteration

Jonas Mersholm
Reply

Hi all!

 

How would i go around iterating an ItemList inside a item object with razor.  

 

I am trying the following

       @foreach(LoopItem l in GetLoop("ItemPublisher:Items.List")) {
      foreach(LoopItem li in l.GetLoop("ItemPublisher:Item.Billeder")) {
            @li.GetValue("ItemPublisher:Item.Billede");        
      }

}

But without any luck

 


Replies

 
Jonas Mersholm
Reply

It turns out you have to use the complete path every time you call a variable. This is the correct solution

       @foreach(LoopItem l in GetLoop("ItemPublisher:Items.List")) {
            foreach(LoopItem li in l.GetLoop("ItemPublisher:Item.Billeder")) {
                 @li.GetValue("ItemPublisher:Item.Billeder.Billede");
                    <br>

             }
      }

 

For those who might wonder how to grab simply a single item from the subitems. You may do this

@l.GetLoop("ItemPublisher:Item.Billeder")[0].GetValue("ItemPublisher:Item.Billeder.Billede")

Where [0]  defines the index of the item, ( Starting from 0 ofcourse )

 
Nicolai Høeg Pedersen
Reply

Hi Jonas

Yes you need the entire tag paht. And thanks for sharing the result!

Nicolai

 

You must be logged in to post in the forum