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

    I'm trying to output a list of pages using wayfinder. Each page has a template variable that is a link. If this is set I want to output the name of the page as a link to the url specified in the tv. If the tv is not set, I just want to output the name of the page.

    What I want to know is how do I use snippets to output the relevant html?

    So far I have it working so far that it displays the following row template:

    <li>
    <a href="[[processTV? &myId=`[[+id]]` &myTV=`assemblyInstructions` ]]" title="[[+wf.title]]" [[+wf.attributes]]>[[+wf.linktext]]</a>
    [[+wf.wrapper]]
    </li>


    Using this snippet:
    <?php
    $doc = $modx->getObject('modResource', $myId);
    return $doc->getTVValue($myTV);


    Obviously this makes everything a link, but some of the hrefs are blank.

    I want to change it so that if the tv is not set it just outputs the linktitle with no anchor.
    Please help! I've been trying all morning with no success!
      • 31946
      • 116 Posts
      Set a placeholder of the processed TV:
      <?php
      $doc = $modx->getObject('modResource', $myId);
      $value = $doc->getTVValue($myTV);
      $modx->toPlaceholder('myhref',$value);
      return '';
      

      And then in your template, you could check with the "notempty" Output modifier, if you have a value:
      [[processTV? &myId=`[[+id]]` &myTV=`assemblyInstructions` ]]
      [[+myhref:notempty=`<a href="[[+myhref]]" title="[[+wf.title]]" [[+wf.attributes]]>[[+wf.linktext]]</a>`:else=`<a title="[[+wf.title]]" [[+wf.attributes]]>[[+wf.linktext]]</a>`]]

      Not tested but if i remember right, this should be possible..