Developer forum

Forum » Rapido » Product Grid-List Customization issue - not ok when clicking "Grid view" / working well on Reload page

Product Grid-List Customization issue - not ok when clicking "Grid view" / working well on Reload page

Lara Arsénio
Reply

Creating a Custom Block for GridView, set inside script id=ProductGridItemContainer.

I am extending grid list adding a (conditional) data-template before the div id=“ProductGridItem”.

It works well when refreshing the page in Grid Mode, but not when clicking the "Grid View" - it ignores the condition scoped within "ProductGridItemContainer". 

Here is my handlebars loop:

<script id="ProductGridItemContainer" type="text/x-template">
    {{#.}}
        {{#if showGroupName}}
             <div id="TitleProduct{{id}}" data-template="ProductGridTitleItem" class="grid__col-lg-12 grid__col-md-12 grid__col-sm-12 grid__col-xs-12 dw-mod">
                {{#Product}}
                     {{>ProductGridTitleItem}}
                {{/Product}}
            </div> 
        {{/if}}       
        <div id="Product{{id}}" data-template="ProductGridItem" data-preloader="overlay" class="grid__col-lg-@columnsCount grid__col-md-@columnsCount grid__col-sm-@columnsCount grid__col-xs-6 product-list__grid-item @imageZoomOnHover dw-mod">
            {{#Product}}
                 {{>ProductGridItem}}
            {{/Product}}
        </div>
    {{/.}}
</script>

The "ShowGroupName" bool, that seems to be ignored, has been added to the feed in the same scope as the "template" string

(Also, see video repro of product list)

https://www.loom.com/share/524eff0069484e3ea34f51306f9c59fc

Assuming any template inside "ProductGridItemContainer" would be refreshed when switching views, am I missing some requirement, or handlebars rule?


Replies

 
Nicolai Pedersen
Reply

Hi Lara

I cannot answer I am affraid - I've asked a developer to provide an answer.

BR Nicolai

 
Konstantin Landyshev
Reply

Hi Lara

It's quite hard to say what's wrong with your code.
I tried to reproduce your problem, but all works fine for me.
I created next template for title (it's just example for check problems)

<script id="ProductGridTitleItem" type="text/x-template">
  {{#.}}
    <b>some test info</b>
    {{name}}
  {{/.}}
</script>


And here's changed ProductContainer class from productListFeed.cshtml

public class ProductsContainer
{
  public bool showGroupName { get; set; }
  public string template { get; set; }
  public string id { get; set; }
  public List<Product> Product { get; set; }
}


And then I set this variable to true in the start of Products loop

foreach (LoopItem product in GetLoop("Products"))
{
  zIndex--;
  count++;
  ProductsContainer productsContainerObject = new ProductsContainer();
  productsContainerObject.template = listMode;
  productsContainerObject.id = count.ToString();
  productsContainerObject.Product = new List<Product>();
  productsContainerObject.showGroupName = true;


ProductGridItemTemplate I took from your message.

All works correct. So I can assume - you may have problem in ProductGridTitleItem or some mistake in feed template where you set showGroupName to true.
You also can try to move showGroupName logic from feed directly to gridView cshtml file (if this bool variable is not depend of product data) - for example like this

<script id="ProductGridItemContainer" type="text/x-template">
  {{#.}}
    @{ bool showGroupTitle = true; }
    @if (showGroupTitle) {
      <div id="TitleProduct{{id}}" data-template="ProductGridTitleItem" class="grid__col-lg-12 grid__col-md-12 grid__col-sm-12 grid__col-xs-12 dw-mod">
        {{#Product}}
          {{>ProductGridTitleItem}}
        {{/Product}}
      </div> 
    }
    ...

It can be helpfull if calculating this variable can be done once, instead of multiple times in products loop.

Best regars
Konstantin Landyshev

 
Lara Arsénio
Reply

Hi Konstantin, thanks for the repro.

Here is a video that illustrates the Issue: https://www.loom.com/share/c410804342854e8883ea2124d4e8c274

The var showGroupName needs to be defined in the ProductListFeed, in each product - so it would only return true in some condition. And returns accurate / valid value, when is interpreted. 

I assume that Handlebars is doing (or failing to do) is to interpret this var. Or that I am not using it as it should, but cant see why.

I use the same var both in ListView and GridView mode, but get this problem only in GridView, where I need to create a specific data-template for the Title element. 

- What I see is the handlebars conditional statement {{#if showGroupName}} and var  {{showGroupName}} is only processed when:

   a) the page is reloaded 

  b) Triggering Button GridView or ListView:  only working if all logic is within the Template ProductGridItem

The problem is the var is being ignored, when the switch list is triggered trough the button.

Can you confirm that the logic worked well for you, when "showGroupName" is only defined within the feed, but not as a @razor var above the iteration?

{{#if showGroupName}}
     <div id="TitleProduct{{id}}" data-template="ProductGridTitleItem" class="grid__col-lg-12 grid__col-md-12 grid__col-sm-12 grid__col-xs-12 dw-mod">
        {{#Product}}
             {{>ProductGridTitleItem}}
        {{/Product}}
    </div> 
{{/if}}    

 

 

You must be logged in to post in the forum