Developer forum

Forum » Templates » Razor loops
Keld Lauge Gøtterup
Reply

im trying to use razor templates on an ecom product template but ive run into a problem.

code in oldschool template

  <div id="RelatedGroups" class="eComList"> 
    <!--@LoopStart(ProductRelatedGroups)-->
    <div class="RelatedHeader"><!--@Ecom:Product:RelatedGroup.Name--></div>
    <!--@LoopStart(RelatedProducts)-->
    
    <div class="eComContainer Position<!--@RelatedProducts.LoopMod4-->">
      <div class="BoxHeader">
        <h2><!--@Ecom:Product.Name--></h2>
      </div>
 </div>
    <!--@LoopEnd(RelatedProducts)--> 
    <!--@LoopEnd(ProductRelatedGroups)--> 
  </div>

But if i want to do the same thing in Razor it will give an issue with the loop i another loop

this i the pseudocode which will not work atm.

@:  <div id="RelatedGroups" class="eComList"> 
    foreach (LoopItem i in GetLoop("ProductRelatedGroups")){
@:    <div class="RelatedHeader">@i.GetValue("Ecom:Product:RelatedGroup.Name")</div>

    foreach (LoopItem i2 in i.GetLoop("RelatedProducts")){
    
@:    <div class="eComContainer Position @i2.GetValue("RelatedProducts.LoopMod4")">
@:      <div class="BoxHeader">
@:        <h2>@i2.GetValue("Ecom:Product.Name")</h2>
@:      </div>
@:    </div>
    } 
    } 
@:  </div>

The first loop works  but the inner loop won't

Any ideas on how to do this?


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

 

Can you define "does not work"? The following should work:

 

  <div id="RelatedGroups" class="eComList"> 
    @foreach (LoopItem i in GetLoop("ProductRelatedGroups")){
    <div class="RelatedHeader">@i.GetValue("Ecom:Product:RelatedGroup.Name")</div>
    @foreach (LoopItem i2 in GetLoop("RelatedProducts")){
    var className = "eComContainer Position" + @i2.GetValue("RelatedProducts.LoopMod4");
    <div class="@className">
      <div class="BoxHeader">
        <h2>@i2.GetValue("Ecom:Product.Name")</h2>
      </div>
 </div>
    } 
    } 
  </div>

 

 

Cheers,

 

Imar

 
Keld Lauge Gøtterup
Reply
@:  <div id="RelatedGroups" class="eComList"> 
    foreach (LoopItem i in GetLoop("ProductRelatedGroups")){
@:    <div class="RelatedHeader">@i.GetValue("Ecom:Product:RelatedGroup.Name")</div>

    foreach (LoopItem i2 in GetLoop("RelatedProducts")){
    var className = "eComContainer Position" + i2.GetValue("RelatedProducts.LoopMod4");
@:    <div class="@className">
@:      <div class="BoxHeader">
@:        <h2>@i2.GetValue("Ecom:Product.Name")</h2>
@:      </div>
@:      <div class="Holder"> <a href="@i2.GetValue("Ecom:Product.LinkGroup.Clean")">
@:        <div class="eComImageHover"></div>
@:        <div class="eComImage"> <img src="/admin/public/getimage.ashx?Image=/Files/Images/ProduktBilleder/@i2.GetValue("Ecom:Product.Number")_1.png&Format=png&Resolution=72&Width=201&Height=110&Crop=5&amp;altFmImage_path=/Files/Images/Testbilleder/GroupImageDummy.png" border="0" alt="@i2.GetValue("Ecom:Product.Name")" title="@i2.GetValue("Ecom:Product.Name")"> </div>
@:        <div class="eComTeaser">
@:          <p>@i2.GetValue("Ecom:Product.ShortDescription")</p>
@:          <p class="Link">L&aelig;s mere</p>
@:        </div>
@:        </a> </div>
@:    </div>
    } 
    } 
@:  </div>


basically the problem is it never enters the second loop...

 

 
Dmitrij Jazel
Reply

Hej Imar, Keld,

I actually have exactly the same problem here:

http://developer.dynamicweb-cms.com/forum/templates/related-products-listing-problem.aspx

Imar, are you sure this works?

I just tryed your example... I am able to get "@i.GetValue("Ecom:Product:RelatedGroup.Name")" out... but it does not go into inner loop.

I have some more places where I must use inner loops (custom product fields for example) would be great to get some kind of solution for it! :)))

 

//Dmitrij

 

 

You must be logged in to post in the forum