New to Kentico 10, Looking for examples of code required for Transformations

Robert Srigley asked on January 19, 2018 20:43

I am new to Kentico 10 and have been looking through the documentation for examples of your transformation methods, not just a description.

For example, I have created a hierarchical transformation of my bootstrap 4.0 menu code. I now need to test a link to see if it is active and if so, set the class to include "active".

The transformation method I am using is ascx and it uses the Boolean Method IfTrue and it against uses the Boolean Method IsDocumentOnSelectedPath as it's first arguement.

What is the specific code I need to make the follwing work; <li class="nav-item <%# IfTrue(IsDocumentOnSelectedPath()),"active" %>"><%# Eval("MenuItemName") %> <cms:SubLevelPlaceHolder runat="server" Id="plcSub" />

Thank you.

Correct Answer

Prashant Verma answered on January 19, 2018 21:06

Hi Robert,

You can simply use ternary condition to check and set active state. <li class="nav-item <%# IsDocumentOnSelectedPath()? "active":"" %>"><%# Eval("MenuItemName") %> <cms:SubLevelPlaceHolder runat="server" Id="plcSub" />

Thanks

Happy to help!

0 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on January 20, 2018 00:50 (last edited on January 20, 2018 00:51)

Your syntax is just a bit off, you had a closing ) after IsDocumentOnSelectedPath(), and not one after the "active"

<li class="nav-item <%# IfTrue(IsDocumentOnSelectedPath(),"active") %>"><%# Eval("MenuItemName") %> <cms:SubLevelPlaceHolder runat="server" Id="plcSub" />

I would look at text/xml Transformations so you can use Macros as well, the nice thing about macros is they give you some 'intellisense' so you can get a little more info on the objects available and stuff.

0 votesVote for this answer Mark as a Correct answer

Robert Srigley answered on January 23, 2018 16:41 (last edited on January 23, 2018 16:42)

Both of these solutions work, one other question how do you add the accessibility code <span class="sr-only">(current)</span> to the tag that is set to active?

0 votesVote for this answer Mark as a Correct answer

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