Hi everyone,
I am attempting to use a transformation to create a 2 level navigation with dropdowns. I am using the below code to try and highlight the navigation item, if a page within the dropdown is selected. This works ok in the development environment but we are having issues deploying this. We think it is because the page ids are different between the systems.
When using the macro debug feature, we can see different page ids than the ones we see in the database so I'm not sure what has happened. Any ideas?
{% if (IsCurrentDocument() || (NodeHasChildren && CurrentDocument.Parent.Id == NodeId)) { return "active" } else { return "" } %}
This code is potentially problematic:
CurrentDocument.Parent.Id == NodeId
Please, always compare same properties:
CurrentDocument.Parent.NodeID == NodeID
Also, there is already a macro for this:
IsDocumentOnSelectedPath()
IDs are different, but that shouldn't be an issue unless they are hardcoded in transformation or somewhere else.
What is your issue? Could you please provide more details? Does it adds classes to menu items? Are appropriate CSS classes implemented in production?
What's the web part are you using for your menu? Look at Best Practices for Implementing Site Navigation in Kentico. Two-level menu can be easily done with Hierarchical viewer web part.
Thanks Jan Hermann, this is exactly what we needed. The solution is now simply:
{% if (IsDocumentOnSelectedPath()) { return "active" } else { return "" } |(identity)GlobalAdministrator%}
Please, sign in to be able to submit a new answer.