SubLevel condition in Hierarchical Viewer transformation

rafik maher asked on November 8, 2015 20:28

Good day,

I have a question about ^SubLevelPlaceHolder^ in IfEmpty condition. I am trying to put a class in

  • if there is sublevel in the menu. I tried <%# IfEmpty({^SubLevelPlaceHolder^}, EvalText("class=\"parent\""), EvalText("")) %> but it didn't work.I tried to find another macro for sublevel but I didn't find any.

    Can someone help me please. Thank you

  • Recent Answers


    Maarten van den Hooven answered on November 9, 2015 08:43

    Instead of checking if the SubLevelPlaceHolder is empty, you can check if node has children with this code <%# IfCompare(Eval("NodeChildNodesCount"),0,"Children","NoChildren") %>

    1 votesVote for this answer Mark as a Correct answer

    rafik maher answered on November 9, 2015 16:00

    Hi,

    I put this macro in Item transformation Level 0 to detect node children but it show the class to all pages who has child or no child Level1.<li <%# IfCompare(Eval("NodeChildNodesCount"),0,"class=\"parent\"","") %>>.

    0 votesVote for this answer Mark as a Correct answer

    Maarten van den Hooven answered on November 9, 2015 17:53 (last edited on December 10, 2019 02:30)

    Hi Rafik,

    Sorry I now see that this is removed in Kentico 8.2.

    I have two solutions:

    1. Change your transformation to XML, this also performance better and then use this :

      {% Documents.Where("NodeID = " + NodeID).FirstItem.Children.Count > 0 ? "class=\"parent\"" : String.Empty |(identity)GlobalAdministrator%}

    2. Or write your own function like described here : http://devnet.kentico.com/questions/child-node-count-in-transformation

    0 votesVote for this answer Mark as a Correct answer

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