Developer forum

Forum » CMS - Standard features » Razor Navigation

Razor Navigation

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I see that Rapido 3.3 has a Navigation paragraph that is using NavigationTreeNodeViewModel

Is this the way forwards for rendering the navigation? Can this be extended to support also ecoomerce navigation (Groups)? And maybe include easy access to the PageItemType or Group Properties?

Thank you,

Adrian


Replies

 
Nicolai Pedersen
Reply

Yes it is.

It supports Ecommerce navigation if you set it up on the page as with the existing navigation.

Then just some markup:

<section>
        @{
            var navigationSettingsMain2 = new Dynamicweb.Frontend.Navigation.NavigationSettings()
            {
                StartLevel = 1,
                StopLevel = 3,
                ExpandMode = Dynamicweb.Frontend.Navigation.ExpandMode.All
            };

            NavigationTreeViewModel navigation2 = GetNavigation(navigationSettingsMain);

        }

        @ShowNavigationTree(navigation2.Nodes);

        @helper ShowNavigationTree(IEnumerable<NavigationTreeNodeViewModel> nodes)
        {
            <ul>
                @foreach (var node in nodes)
                {
                    <li>@node.Name
                        @ShowNavigationTree(node.Nodes)
                    </li>
                }
            </ul>
        }
    </section>
Capture.JPG Capture2.JPG Capture3.JPG
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Awesome. Then, I will have to use PageService or GroupService to get additional details?

Is there any way to tell if the node is a Group or a Page? It appears that the NavigationTreeNodeViewModel exposes only the basic information about the node. It would be useful to have information about the type (Page or Group), ItemType and ItemTypeID (for pages)

Thank you,

Adrian

 

 
Nicolai Pedersen
Reply

Hi Adrian

A node type (Group or page) and a type id (Groupid or pageid) will be useful and needed to get hold of more data. Item, page and group data you will not get out of the model as it is designed to be fast - and then you can add all the slow custom code you want in the template :-).

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I understand pretty awesome.
I was not talking about the actual data of the ItemType. Just the ItemType SystemName and ItemTypeID. In case I want to add all the slow code :)

Anyway, I am trying a different approach for mega menu navigation, using the new VisualBuilder.

Will see where I get to :)

Thank you,
Adrian

 
Nicolai Pedersen
Reply

You do not need itemtype and id.

You have the pageid and then get the page from the pageservice - the page has the itemtype and id - and item instance also.

@helper ShowNavigationTree(IEnumerable<NavigationTreeNodeViewModel> nodes)
        {
    
            <ul>
                @foreach (var node in nodes)
                {
                    var page = null;
                    if (node.Level == 1) { page = Dynamicweb.Services.Pages.GetPage(node.PageId);}
                    
                    <li>@node.Name
                        @ShowNavigationTree(node.Nodes)
                    </li>
                }
            </ul>
        }
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you. I just needed the ItemTypeSytemName and ID as strings.

But I can totally use PageService to get them.

Thank you,

Adrian

 

You must be logged in to post in the forum