We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29883
    • 15 Posts
    I don’t know much about PHP and so I will ask you for help.

    I need a little snippet that will look if there is a value in a certain TV or not. Lets say, there is a TV called "name". If the user has put in a name (let’s say MODx wink the output should be <p>MODx</p>. If the TV ist empty the snippet should return nothing.

    How can I achieve this?

    Thanks

    Mazso

      • 25663 MODX Staff
      • 12,272 Posts
      I believe the API call you’d need to use is outlined here: http://modxcms.com/gettemplatevar.html
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 29883
        • 15 Posts
        Yes, thank you, I think that’s what I’m searching for. I tried beforehand to find out how this getTemplateVarOutput works - but couldn’t made it out sad

        Sorry, but could you could give me another hint what to do with this $idname=array(), $docid="", $published="1" stuff to extract the value of a TV?
          • 33372
          • 1,611 Posts
          This should do what you need:

          $output='';
          
          $idname=$modx->getTemplateVarOutput('name',$modx->documentIdentifier);
          
          if($idname['name']!='') $output.='<p>'.$idname['name'].'</p>';
          
          return $output;


          Sometimes it can be confusing that this function returns an array (which is why you need to refer to your name value as $idname[’name’]). But once you realize that it’s pretty straightforward (and you can get the values of several TVs with one line of code). The only problem that I’ve had with this particular function is that if you use it to get the output of a TV with multiple values (listboxes and checkboxes), it returns them all as one long string with no separators, so if you need to do that don’t try to use this function (a regular query works better).

            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 29883
            • 15 Posts
            Thank you Zap, that’s what I was looking for.