Developer forum

Forum » Development » DW 8.9.2.6 - VariantCombinations loop is empty if TemplateTags() not present in template...

DW 8.9.2.6 - VariantCombinations loop is empty if TemplateTags() not present in template...

Jacob Storgaard Jensen
Reply

Hi,

I'm doing some small changes to an old site, and just stumbeled across a weird behavior.

Trying to build a Google Shopping feed, but when I try to render variants they turn out empty.

Simplifyed code which doesn't render anything in the second foreach:

@foreach (LoopItem i in GetLoop("Products")){
    var variants = i.GetLoop("VariantCombinations");
    <item>
       <g:title>@i.GetValue("Ecom:Product.Name")</g:title>
    </item>

    if(variants.Any()){
        foreach (LoopItem v in variants){
            <item>
                <g:title>@v.GetValue("Ecom:Product.Name")</g:title>
            </item>
        }
    }
}

If I then add TemplateTags() somewhere, doesn't matter where... the second foreach will render...

@TemplateTags()
@foreach (LoopItem i in GetLoop("Products")){
    var variants = i.GetLoop("VariantCombinations");
    <item>
       <g:title>@i.GetValue("Ecom:Product.Name") OR HERE @i.TemplateTags()</g:title>
    </item>

    if(variants.Any()){
        foreach (LoopItem v in variants){
            <item>
                <g:title>@v.GetValue("Ecom:Product.Name")</g:title>
            </item>
        }
    }
}

Am I doing something wrong here, or is this a bug?


Replies

 
Nicolai Pedersen
Reply

Try to not put the loop into a variable, but use i.GetLoop("VariantCombinations") directly.

 
Jacob Storgaard Jensen
Reply

P.S.

I actually have the somewhat same behaviour in an HTML-template on this site. If I add <!--@DwTemplateTags--> just before the <!--@LoopStart(VariantCombinations)--><!--@Ecom:Product.Name--><!--@LoopEnd(VariantCombinations)--> the product names will render... if I remove the DwTemplateTags it wont...

 
Jacob Storgaard Jensen
Reply
Original message by Nicolai Pedersen posted on 20/03/2019 13:59:03:

Try to not put the loop into a variable, but use i.GetLoop("VariantCombinations") directly.

I did that before, and just tested again, it behaves exactly the same...

 
Jacob Storgaard Jensen
Reply

Okay, so it seems like it's related to the setting "Show default variant in product list"... when I turn this one OFF it will render the VariantCombinations loop just fine. Both in Razor and HTML...

This will give me some issues in other product lists, but then a workaround will be to check if VariantCount > 0 and then render default variant otherwise render "normal product"...

 

You must be logged in to post in the forum