Developer forum

Forum » Templates » Loop.Contains empty when it should not be

Loop.Contains empty when it should not be

Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Hello, I am debugging a strange issue with the following code. The issue is that sometimes the Loop.Contains returns false, even if I have verified that the variants exist in DW, and after some time I reload the page again and it is true and everything works... and then this repeats itself.

The solution is using DW 9.10.11 as of now but I know that this issue did also persist when we were using 9.9.8 recently.

                        <div class="store-location" id="@variant.GetString("Ecom:VariantCombination.VariantID")" style="display: none;">
                            @if (Loops.Contains(@variant.GetString("Ecom:VariantCombination.VariantID")))
                            {
                                foreach (var item in GetLoop(@variant.GetString("Ecom:VariantCombination.VariantID")))
                                {
                                    if (item.GetBoolean("Value"))
                                    {
                                        <div class="product-in-stock" data-location-code="@item.GetString("ID")"> - @item.GetString("Name") </div>
                                    }
                                }
                            }
                            else
                            {
                                <div class="product-in-stock" data-location-code="webshop-only"> - Aðeins til í vefverslun </div>
                            }
                        </div>

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

.Loops is a LoopCollection that looks like this:

So when you do contains, you feed it a variantid... And there should be no loops with the variant id as a key. The key is the name of the loop - i.e. "Variants" or "VariantGroups"

Looking at your code I see weird things...Doing GetLoop(@variant.GetString("Ecom:VariantCombination.VariantID")) looks fundamentally wrong unless you made some custom loop code that uses the IDs as loopnames...

Votes for this answer: 1
 
Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

Ok thank you for the answer, this code is not written by me and I could not find any place where we are making custom loops, I will have to do a better search.

 

You must be logged in to post in the forum