How to test for NodeHasChildren in ascx transformations for multilevel menuing

Robert Srigley asked on January 23, 2018 17:52

The article Best Practices for Implementing Site Navigation in Kentico written by Ondrej Vasil May 13, 2015 indicates you can use the following Subitems Check; {% if (NodeHasChildren) { return "has-subitems" } %}

How is this used in ascx transformations and what is the Syntax to display a sublevel menu?

I need to adjust the classes and attribute for my tag if I am on the second level.

I am unsure how to code this in my hierarchical transformation.

The zero level in my hierarchical transformation needs to output the following; <li class="nav-item active"><a class="nav-link active" href="#">Home <span class="sr-only">(current)</span></a></li>

The one level in my hierarchical transformation needs to output the following html; <li class="nav-item dropdown"><a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Pages</a>

Correct Answer

Michal Novák answered on January 26, 2018 09:01

Try to use this code. Don't forget add NodeHasChildren into columns property of Hierarchical viewer web part.

<li class="nav-item<%# Eval<bool>("NodeHasChildren") ? " dropdown" : "" %>">

1 votesVote for this answer Unmark Correct answer

Recent Answers

Robert Srigley answered on January 26, 2018 14:27 (last edited on January 26, 2018 14:37)

This worked and I had to add the following fields to the Hierarchical Transformation web part config;

NodeSiteID, MenuItemName, NodeAliasPath, DocumentUrlPath

Thank you so much for the help.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.