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

    i need to check to see if a TV exists for any given document and if it does return it along with another chunk of code and if it does exist or has not been set then return nothing.

    my TV is called "ZoomImage" and is just an image input with html entity widget.

    i’ve tried something along the lines of the following but can’t get it right

    $thisID = $modx->documentObject['id'];
    $tvs = $modx->getTemplateVarOutput('ZoomImage', $thisID);
    
    if(isset($tvs['ZoomImage'])){
        return '<div id="ZoomButton"><a href="'.$tvs['ZoomImage'].'" rel="lightbox"><img src="assets/siteimages/layout/zoomin.gif" alt="Click to enlarge image" border="0" /></a></div>'
    }


    i know something like this is possible but i can’t find any usage example on how to use the getTemplateVar API functions.

    thanks! smiley
      • 29181
      • 480 Posts
      Maybe getField would be a snippet you could use to save you reinventing the wheel?

      It’s saved me a lot of messing around, a lot of times.

      Taff
        Adrian Lawley: www.adrianlawley.com
        • 12151
        • 115 Posts
        hehe! superstar!!

        thanks smiley
          • 10194
          • 16 Posts
          Hi Highlander, I know that the getField can probably do what you want, but you were on to something with the getTemplateVarOutput, but instead of the

          if(isset($tvs[’ZoomImage’]))

          use !empty

          if(!empty($tvs[’ZoomImage’]))

          seemed to work for me....personally, I’d rather use a few lines of code instead of installing another snippet.

          - Fritz