Developer forum

Forum » Templates » Looping nested ItemRelations not going deeper than level 2

Looping nested ItemRelations not going deeper than level 2

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

using Items, i have built an app that uses nested ItemRelations in 3 levels. This is used to create a 3 level list similar to this:

* continent a
        country a
              shop_a1
              shop_a2
              shop_a3
        country b
              shop_b1
              shop_b2
* continent b
        country c
              shop_c1
              shop_c2
              shop_c3
        country d
              shop_d1
              shop_d2

 

Now, the problem is that Dynamicweb aparantly will not create a loop if the item relation is a level3 item. My template looks similar to below, and I get result/output in level1 and level2 - but get no result in level3

@foreach(LoopItem a in GetLoop("Item.level1")){

   @a.TemplateTags() //Gives a result

      foreach(LoopItem b in a.GetLoop("Item.Level1.Level2")){

           @b.TemplateTags() // Gives a result

               foreach(LoopItem c in b.GetLoop("Item.Level1.Level2.Level3")){

            @c.TemplateTags() // Gives no result

           }

     }

}
 

Any ideas or suggestions on what to do, or is this a bug?

 

/Hans


Replies

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Does anyone know if there is a restriction in number of  nested loops, or is this a bug, or am I doing something wrong?

/Hans

 
Nicolai Pedersen
Reply

Hi Hans

I do not think we ever tested that, might be a limitation.

What version are you on?

BR Nicolai

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Nicolai

 

version 9.10.13

 

/Hans

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi all,

yes, there is a limitation of nested levels inside items rendering.

Many years ago it was desided that 2 levels should be enough for everyone...

 

Best regards

Vladimir

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Ok, I really think you should reconsider extending that to  3 levels

But for now, is there no other way of looping throug level 3 elements?

/Hans

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

it should be still possible to do same with API, e.g.:

@{
    var itemList = Dynamicweb.Content.Items.ItemList.GetItemListById(Converter.ToInt32(value from b));
    <select>
        @foreach (var item in itemList.Relations.Cast<Item>())
        {
            <option>@item["Name"]</option>
        }
    </select>
}

Best regards,

Vladimir

 

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Perfect, Vladimir  👍🏻

works like a charm

 

You must be logged in to post in the forum