We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10190
    • 187 Posts
    Hello,

    I need some help for porting a wayfinder menu from modx 0.9.6.3, Wayfinder2.5beta2 with PHx to Revolution.

    As far as I understand from the fine manual I should use Custom Output Filters instead of PHx. But before I start coding the snippets, I’d like to know from you whether this could be done at all?

    Here’s my chunk’s code:
    [+phx:if=`[[+wf.level]]`:is=`1`:then=`
    <li class="top [[+wf.classnames]]"><a href="[[+wf.link]]" class="top_link">[[+wf.linktext]]</a>[[+wf.wrapper]]</li> `:else=`
    <li class="[[+wf.classnames]]"><span><a href="[[+wf.link]]">[[+wf.linktext]]</a></span>
    [[+wf.wrapper]]</li> 
    `+]
    


    I guess I have to replace the chunk’s code with s.th. like:
    [[CheckWfLevel? &level=`[[+wf.level]]`]]

    which would not be a Custom Output Filter, but an ordinary snippet call.

    The snippet should return the html code (see above) depending on wf.level including wf.* placeholders so wayfinder can process them furtheron.

    Could you please clearify that to me - am I right to do it that way?

    Cheers
    Frisco
      • 10190
      • 187 Posts
      Hmpf,

      sometimes you should just dare to try, the following snippet call works - but the menu is not built the proper way:

      Call within chunk:
      [[CheckWfLevelParentRow? &level=`[[+wf.level]]`]]


      Snippets code:
      <?php
      $return='';
      $level = !empty($level)?$level:"Fehler: Options war nicht gesetzt!";
      if ($level==1) {
      $return = '<li class="top [[+wf.classnames]]"><a href="[[+wf.link]]" class="top_link">[[+wf.linktext]]<!--[if gte IE 7]><!--></a><!--<![endif]-->
      		<!--[if lte IE 6]><table><tr><td><iframe></iframe><![endif]-->[[+wf.wrapper]]</li>';
      }
      else {
      $return = '<li class="[[+wf.classnames]]"><span><a href="[[+wf.link]]">[[+wf.linktext]]<!--[if gte IE 7]><!--></a></span><b></b><!--<![endif]-->
      				<!--[if lte IE 6]><table><tr><td><iframe></iframe><![endif]-->
      [[+wf.wrapper]]</li>';
      }
      return ($return);


      So the snippet call from the chunk works, but wayfinder seems to iterate the document tree wrong, the menu is being output as follows:

      - Folder 1
      - Subitem 1.a
      - Folder 2
      - Subitem 2.a
      - Folder 1
      - Subitem 1.a
      - Folder 1
      - Subitem 1.a
      - Folder 1
      - Subitem 1.a

      instead of:

      - Folder 1
      - Subitem 1.a
      - Folder 2
      - Subitem 2.a
      - Folder 3
      - Subitem 3.a
      - Folder 4
      - Subitem 4.a
      - Folder 5
      - Subitem 5.a

      Any ideas what goes wrong?

      Cheers
      Frisco
        • 10190
        • 187 Posts
        I guess the problem is that wayfinder doesn’t process the output from the snippet. As far as I understood, the wf.* placeholders let wayfinder nest the ul and li tags.

        Should I return the snippets output another way (via modx API) or is there any other way to add logic to wayfinder’s chunk like with PHx in former versions?

        Cheers
        Frisco
          • 10190
          • 187 Posts
          Hi folks,

          solved it now with the great "If" snippet.

          I don’t know why this one works and my snippet not, as both return the html with the placeholders included according to conditional logic.

          The only difference is that you have to send the html as an input parameter to "If", while my snippet has the HTML in it’s code. I remember that one should not mix html with PHP snippet code, so maybe it’s about that.

          Anyway, for anyone interested here is the wayfinder chunk for "&parentRowTpl" with the call to "If":

          [[If?
             &subject=`[[+wf.level]]`
             &operator=`EQ`
             &operand=`1`
             &then=`<li class="top [[+wf.classnames]] menucolor3"><a href="[[+wf.link]]" class="top_link">[[+wf.linktext]]<!--[if gte IE 7]><!--></a><!--<![endif]-->
          		<!--[if lte IE 6]><table><tr><td><iframe></iframe><![endif]-->[[+wf.wrapper]]</li>`
             &else=`<li class="[[+wf.classnames]] menucolor3"><span><a href="[[+wf.link]]">[[+wf.linktext]]<!--[if gte IE 7]><!--></a></span><b></b><!--<![endif]-->
          				<!--[if lte IE 6]><table><tr><td><iframe></iframe><![endif]-->
          [[+wf.wrapper]]</li>`
          ]]
          


          So if you need logic in your wayfinder templates use it like this.

          Cheers
          Frisco
            • 3749
            • 24,544 Posts
            I’m glad you got it sorted. Thanks for reporting back. cool
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting