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

    I have a url template variable with a default value of "none".

    For pages with a custom url that I type in this field I want it to display a link with the specified url, however for pages with simply the default value of "none" in the url field I don’t want anything to display.

    This is the snippet that decides what to display.

    <?php
    $cslink = "[+CaseStudy+]";
    if($cslink != "none"){
    echo '<a href="[+CaseStudy+]">Case Study</a>';
    }
    elseif($cslink == "none"){
    echo "";
    }
    ?>


    It works without the elseif statement, however the Case Study link is displayed on all the pages. When I take out the elseif statement then it won’t display anywhere.
      • 4041
      • 788 Posts
      Give this a try:
      <?php
      
      $thisid = $modx->documentIdentifier;
      $output ='';
      $cslink = $modx->getTemplateVarOutput(array("CaseStudy"), $docid=$thisid);
      
      if($cslink['CaseStudy'] != "none"){
          $output .='<a href="'.$cslink['CaseStudy'].'">Case Study</a>';
      }
      
      return $output;
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution