Developer forum

Forum » Templates » Show only product groups with "Show in menu" checked

Show only product groups with "Show in menu" checked

Andrey Kozachuk
Reply

Hello,

I have a paragraph with Product Catalog module that shows groups by default.

I want to show only those groups that have "Show in menu" checkbox checked in group details.

I try to use following razor template:

 @foreach (LoopItem item in GetLoop("Groups"))
    {
        if (@item.GetBoolean("Ecom:Group.NavigationShowInMenu"))
        {
          <span>@item.GetValue("Ecom:Group.Name")</span>      
        }
    }

The problem is that "NavigationShowInMenu" is always false.

How should I change the template to make it work?

Thanks


Replies

 
Nicolai Høeg Pedersen
Reply

You should not write if (@item.GetBoolean("Ecom:Group.NavigationShowInMenu"))

Just try if (item.GetBoolean("Ecom:Group.NavigationShowInMenu"))

NP

 
Andrey Kozachuk
Reply

I chanded the template, but it is still not working:
    @foreach (LoopItem item in GetLoop("Groups"))
    {
        if (item.GetBoolean("Ecom:Group.NavigationShowInMenu"))
        {
   <span>@item.GetValue("Ecom:Group.Name")</span>      
        }
    }
 

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

What is the output if you add <span>@item.TemplateTags()</span> inside your loop?

Votes for this answer: 1
 
Andrey Kozachuk
Reply

I forgot about TemplateTags() :) It showed that I should use ShowInMenu instead of NavigationShowInMenu.

Now it works, thanks.

 

You must be logged in to post in the forum