We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10780
    • 69 Posts
    I have a template variable that is only for uploading files for users to download. Some of the resources won’t have this content and some will - how do I show the code only if there is content in the resource to download?
      • 4310
      • 2,310 Posts
      Easiest way is to have a separate template and assign the TV to only that template.
        • 10780
        • 69 Posts
        Well it’s from the same resource, so some resources will have downloads and some wont. I know I can have two templates and select the different one if there is no download, but isn’t there a more elegant way of doing it?
          • 4310
          • 2,310 Posts
          how do I show the code only if there is content
          Do you mean the TV in the Manager or the associated html of a possibly empty TV at the front end?
            • 10780
            • 69 Posts
            The latter.

            I basically have this code to display in the front end.

            <a href="[*download*]">Download PDF</a>


            But I only want that code to show if there is actually a file being added to the download field.
              • 4310
              • 2,310 Posts
              Put the code below into a snippet, then call the snippet instead of <a href="[*download*]">Download PDF</a>
              <?php
              $tv = $modx->getTemplateVarOutput(true, $modx->documentIdentifier);
              $value = $tv['download'];
              return empty($value)? "" : '<a href="'.$value.'">Download PDF</a>';
              ?>