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

    EDIT: this was solved with a snippet for Wayfinder and phx for Ditto....

    I am using MODx Evo (1.04) for an intranet site and am having trouble with PHx (2.14) syntax when 3 elements are involved.

    The structure is hierachical so I need to use Wayfinder for the majority of the menus.

    This site has 3 types of content that I need to include in menus etc:
    - standard page
    - pdf page ( represented by a TV called [+pdf+] )
    - link page ( represented by a TV called [+link+] )

    Its one or the other - if a pdf is included, a link cannot be - and vice versa.

    I think what I am trying to say is
    1 if [+pdf+] isnot empty, then [+pdf+] ...or...
    2 if [+link+] isnot empty, then link [+link+] ...or...
    3a if pdf is empty and if link is empty, then [+wf.link+]
    
    vs
    
    1 if [+pdf+] isnot empty, then [+pdf+] ...or...
    2 if [+link+] isnot empty, then link [+link+] ...else...
    3b standard page link (eg [+wf.link+])...
    


    Demo 1 -
    This:
    <li><a href="
    [+phx:if=`[+pdf+]`:isnot=``:then=`[+pdf+]`:else=``+]
    [+phx:if=`[+link+]`:isnot=``:then=`[+link+]`:else=``+]
    [+phx:if=`[+pdf+]`:is=``:and:if=`[+link+]`:is=``:then=`[+wf.link+]`+]
    ">[+wf.linktext+]</a></li>
    
    Returns
    pdf's and links but not standard pages (they return blank - href="" )


    Demo 2 -
    This:
    <li><a href="
    [+phx:if=`[+pdf+]`:isnot=``:or:if=`[+link+]`:isnot=``:then=`[+pdf+][+link+]`:else=`[+wf.link+]`+]
    ">[+wf.linktext+]</a></li>
    
    Returns
    pdf's and links but not standard pages (they return blank - href="" )


    Demo 3 -
    This:
    <li><a href="
    [+phx:if=`[+pdf+]`:isnot=``:then=`[+pdf+]`:else=``+]
    [+phx:if=`[+link+]`:isnot=``:then=`[+link+]`:else=`[+wf.link+]`+]
    ">[+wf.linktext+]</a></li>
    
    Returns
    pdf's and links but not standard pages (they return blank - href="" )
    


    Demo 4 -
    This:
    <li><a href="
    [+phx:if=`[+pdf+]`:isnot=``:then=`[+pdf+]`:else=`
    [+phx:if=`[+link+]`:isnot=``:then=`[+link+]`:else=`[+wf.link+]`+]
    `+]
    ">[+wf.linktext+]</a></li>
    
    Returns
    pdf's and links but not standard pages (they return blank - href="" )



    Aye aye aye...

    I am going round in circles and just wondering if someone could talk some logic into me.

    Any ideas?

    Thanks in advance.
      Web design Adelaide
      http://gocreate.com.au
      • 4172
      • 5,888 Posts
      try:

      [+pdf:is=``:then=`[+link:isnot=``:then=`[+link+]`:else=`[+wf.link+]`+]`:else=`[+pdf+]`+]

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 21417
        • 486 Posts
        Hello Bruno,

        Thanks for replying and for having a crack.

        Unfortunately this one didn’t work at all - everything returned blank href=""....
        [+pdf:is=``:then=`[+link:isnot=``:then=`[+link+]`:else=`[+wf.link+]`+]`:else=`[+pdf+]`+]


        Then I thought perhaps the phx tags are required so I tried this...
        [+phx:if=`[+pdf+]`:is=``:then=`[+phx:if=`[+link+]`:isnot=``:then=`[+link+]`:else=`[+wf.link+]`+]`:else=`[+pdf+]`+]
        
        but I am back to square 1 with that as it returns...
        pdf's and links but not standard pages (they return blank - href="" )



        The syntax might be close?

        Any other suggestions?
          Web design Adelaide
          http://gocreate.com.au
          • 21417
          • 486 Posts
          I have been doing more searching and testing - this post is very related and suggests using a snippet instead of PHx but I am getting a parse error when trying to use BobRay’s snippet:

          http://modxcms.com/forums/index.php?topic=33155.0

          If I create a snippet called "aa-menuTVswitcher":
          <?php
          $tv1_out = $modx->getTemplateVarOutput($tv1);
          $tv2_out = $modx->getTemplateVarOutput($tv2);
          
          if (! empty($tv1_out)) {
              $output = 'tv1';
          } elseif (! empty(tv2_out)) {
              $output = 'tv1';
          } else{
              $output = 'wf.link';
          }
          return $output;
          ?>
          



          And a menu call
          <div>
          [!Wayfinder? &startId=`[*id*]` &textOfLinks=`pagetitle` &ignoreHidden=`true` 
          &outerTpl=`2col-pdf-menu-wrapper` &rowTpl=`pdf-menu-row` !]
          </div>



          With a row template:
          <li[+wf.classes+]><a href="
          [[aa-menuTVswitcher? &tv1=`pdf` &tv2=`link` ]]
          " title="[+wf.title+]"[+wf.attributes+]>[+wf.linktext+][+phx:if=`[+wf.description+]`:is=``:then=``:else=` [+wf.description+]`+]</a>[+phx:if=`[+status+]`:is=``:then=``:else=`<span> * [+status+]</span>`+][+wf.wrapper+]</li>



          The rows show a passing error in the html page source of each link:
          <br />
          <b>Parse error</b>:  syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in <b>...../public_html/manager/includes/document.parser.class.inc.php(770) : eval()'d code</b> on line <b>7</b><br />
          



          Any ideas?

          Beer money via paypal to anyone that can solve this for me.

          Thanks for looking.
            Web design Adelaide
            http://gocreate.com.au
            • 4172
            • 5,888 Posts
            ok, this way seems to work with this snippet:

            <?php
            $tvs = explode(',',$tvs);
            
            foreach ($tvs as $tv){
                if (! empty($tv)) {
                    return $tv;
                } 
            }
            
            return $else;
            ?>


            in your rowTpl:


            <li[+wf.classes+]><a href=" [[switcher? &tvs=`[+pdf+],[+url+]`&else=`[+wf.link+]`]] " title="[+wf.title+]"[+wf.attributes+] >
            [+wf.linktext+]</a>[+wf.wrapper+]</li>


            you may not use ’link’ for the tv-name because wayfinder wants to use it as reserved placeholoder, I named it ’url’

            this will not work with furls off, I think because of the ? in [+wf.link+]

              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 21417
              • 486 Posts
              Hey Bruno,

              Wow, this works a treat in Wayfinder with smart URL’s turned on! Absolutely awesome. Thanks so much.

              Is this how you’d imagine the snippet call would be in Ditto? I can’t get it to work in Ditto:
              [[switchTV? &tvs=`[+pdf+],[+url+]`&else=`[~[+id+]~]`]]


              Any ideas?

              Beer money is coming!

              Thanks a million.
                Web design Adelaide
                http://gocreate.com.au
                • 4172
                • 5,888 Posts
                with Ditto I think this version with phx should work:

                <ul>
                [!Ditto? &hiddenFields=`url,pdf,id` &parents=`173` &tpl=`ditto_switcher`]]
                </ul>


                chunk:
                <li>[+pdf:is=``:then=`[+url:isnot=``:then=`[+url+]`:else=`[~[+id+]~]`+]`:else=`[+pdf+]`+]</li>

                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 21417
                  • 486 Posts
                  You are awesome Bruno!

                  I can confirm that your ditto suggestion works an absolute treat!

                  Thank you so much.

                  So to confirm...

                  For Ditto:

                  I added this to the call:
                  &hiddenFields=`url,pdf,id`


                  and in the href="" link of the Ditto template I added:
                  [+pdf:is=``:then=`[+url:isnot=``:then=`[+url+]`:else=`[~[+id+]~]`+]`:else=`[+pdf+]`+]



                  For Wayfinder:

                  I created a snippet called switcher

                  <?php
                  $tvs = explode(',',$tvs);
                  
                  foreach ($tvs as $tv){
                      if (! empty($tv)) {
                          return $tv;
                      } 
                  }
                  
                  return $else;
                  ?>
                  


                  and in the href="" link of the Wayfinder row template I added:

                  [[switcher? &tvs=`[+pdf+],[+url+]`&else=`[+wf.link+]`]]


                  where [+pdf+] and [+url+] are both template variables.

                  Thank you Bruno!

                    Web design Adelaide
                    http://gocreate.com.au