We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6016
    • 55 Posts
    In my page template, I call Wayfinder, and the rowTpl includes this line:

    <a href="[+wf.link+]" title="[+wf.title+]" [+wf.attributes+]>[+wf.linktext+] [+wf.subitemcount+]</a>

    Wayfinder stuffs the count of children of each menu item into the field [+wf.subitemcount+]. So each menu item lists the number of submenu items under it.

    A year ago, Wayfinder left [+wf.subitemcount+] empty if the number of children was zero. So each menu item had a number against it iff it had nonzero children.

    The latest Wayfinder apparently always stuffs the number into [+wf.subitemcount+], even if zero. This makes the menu look not so nice.

    I am looking for suggestions as to how I can make Wayfinder stuff the parenthesized number into [+wf.subitemcount+] if the number of children is nonzero, else stuff nothing. Then each menu item with other items under it will show a parenthesized number.

    Houses for Sale(132)
    Search
    FAQ(32)
    Contact Us

    Also if you can point me to the right place to read about this in the documentation, I will give that a try.

    Modifying the Wayfinder source code is always one way to solve the problem. I’m looking for a cleaner solution.

    Thanks.

    Rahul

      • 7231
      • 4,205 Posts
      I could not find where this is set in the wf code. However a solution would be to add a snippet to check if it is 0 and if so return "" else return the value:

      <?php
          $count = isset($count) ? $count : '';
          if ($count == 0) {
              $count = "";
          }
          return $count;
      ?>


      Then add it to the rowTpl like this for example:
      <li class="sub">[+wf.linktext+] - [!checkCount? &count=`[+wf.subitemcount+]`!]
      	[+wf.wrapper+] 
      </li>

      Give this a try and see if it does the trick
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 6016
        • 55 Posts
        Excellent! It worked nicely, thanks.

        In the true spirit of functional programming, I changed the snippet code to:

        <?php
        return isset($count) ? $count == 0 ? '' : "($count)" : '';
        ?>
        


        Rahul
          • 7231
          • 4,205 Posts
          Great. Yes your code is much cleaner, thanks.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]