We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33997
    • 150 Posts
    Hi, I want to have a UL displaying a list of links: one parent, and all children. The issue is, I want these all to be in the same UL, and to use the same rowTpl and hereTpl. Is there any way to get the startItem to act as a regular Wayfinder link? Example:
    <ul class="mymenu">
    <li><a href="#">Link One (parent ID:1)</a></li>
    <li><a href="#">Link Two (child of 1)</a></li>
    <li><a href="#">Link Three (child of 1)</a></li>
    <li><a href="#">Link Four (child of 1)</a></li>
    <li><a href="#">Link Five (child of 1)</a></li>
    </ul>
    

    I know I could do this with weblinks (would they register the ’here’ action when a person is on the designated page?) but I would rather not, if anyone knows a way to work around this. Please help!

    P.S. Oh, you should know that I’m using a new Wayfinder call for each menu (they are going in a footer and need to be surrounded by different bits of code). I just thought maybe I should use Ditto, as Ditto allows for changing the display template for every/other. Any ideas?
      "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
      • 22427
      • 793 Posts

      You could try this Wayfinder call:
      [!Wayfinder? &startId=`1` &level=`1` &outerTpl=`myOuterTpl`!]

      where the chunk [tt]myOuterTpl[/tt] contains the following:
      <ul class="mymenu">
      <li><a href="#">Link One (parent ID:1)</a></li>
      [+wf.wrapper+]
      </ul>

      So WF will precede the list of the children links (created through [tt][+wf.wrapper+][/tt] ) by a single [tt]<li>[/tt] element containing the link to the parent.
        • 36442
        • 97 Posts
        Another solution could be like this:
        Wayfinder call:
        [!Wayfinder? &startId=`1` &level=`1` &displayStart=`1` &startItemTpl=`myStartItemTpl` &outerTpl=`myOuterTpl`!]

        myStartItemTpl:
        <ul class="mymenu">
        <li [+wf.classes+]><a href="[+wf.link+]" title="[+wf.title+]">[+wf.link+]</a></li>
        [+wf.wrapper+]
        </ul>

        myOuterTpl:
        [+wf.wrapper+]
          • 33997
          • 150 Posts
          Both really good ideas, thanks! How about getting the startItem to register as ’here’?
            "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
            • 22427
            • 793 Posts
            @Warsteiner:
            <li [+wf.classes+]><a href="[+wf.link+]" title="[+wf.title+]">[+wf.link+]</a></li>
            You certainly meant
            <li [+wf.classes+]><a href="[+wf.link+]" title="[+wf.title+]">[+wf.linktext+]</a></li>
            grin
              • 33997
              • 150 Posts
              @ottogal: I caught that as I was pasting the code in, thanks.

              I got it! I changed a few lines in wayfinder.inc.php and it is all working now. I had to use categoryFoldersTpl for the template instead of defining a new template, because I wasn’t sure where the templates are defined and couldn’t find them, but it is okay, because that site isn’t using the categoryFoldersTpl at all. Here is the code (replaces lines 149-150):

              if ($this->_config['displayStart'] && $resource['level'] == 0 && $resource['id'] != $modx->documentObject['id']) {
              	$usedTemplate = 'startItemTpl';
              } elseif ($this->_config['displayStart'] && $resource['id'] == $modx->documentObject['id'] && $this->_templates['categoryFoldersTpl']) {
              	$usedTemplate = 'categoryFoldersTpl';
              }
              

              The first if adds one additional piece of logic:
              && $resource['id'] != $modx->documentObject['id']

              and the next elseif is totally new, giving a template to startItem when it is the current document.

              Thanks for the help, it got me hunting in the right direction.
                "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
                • 33997
                • 150 Posts
                [UPDATE] Here is the updated code:
                if ($this->_config['displayStart'] && $resource['level'] == 0 && $resource['id'] != $modx->documentObject['id']) {
                	$usedTemplate = 'startItemTpl';
                } elseif ($this->_config['displayStart'] && $resource['level'] == 0 && $resource['id'] == $modx->documentObject['id'] && $this->_templates['categoryFoldersTpl']) {
                	$usedTemplate = 'categoryFoldersTpl'; //***CHANGED END***
                }
                

                Had to add an additional piece of logic into the if statement, to make sure the resource is at the top level only. Otherwise, it was putting the startItemTpl for any page that was current.
                  "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein