We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20063
    • 1 Posts
    I know this is a simple question, ..but i have spent 5 hours over 2 days looking for the answer and now i feel i need to ask.
    I need to reference a template variable i have created for a specific document in a snippet.
    The TV is called [*port_format*] ...and all i want to do is check it’s length in PHP:

    if(strlen('[*port_format*]')>2){ echo "<p><span class='port_label'>FORMAT</span><br />[*port_format*]<p />\n";}


    but i know i cannot refer to the TV like this, ..

    Please help, i know i need to use getTemplateVar, ..but i cannot work out how it works from the documentation.

    Thank yu
      • 22303 MODX Staff
      • 10,725 Posts
      Do you want the raw tv value or the processed output? getTemplateVarOutput would be more appropriate, if the latter is your intention. Both return associate arrays with the first level key representing the TV name.
        • 21257 MODX Staff
        • 730 Posts
        The full PHP, implementing OpenGeek’s suggestion, could be something like:
        $tvOutput = $modx->getTemplateVarOutput(array('port_format'));
        $port_format = $tvOutput['port_format'];
        if(strlen($port_format)>2){ echo "<p><span class='port_label'>FORMAT</span><br />{$port_format}<p />\n";}
        

        .. however, I did not test this, so if it doesn’t work, hopefully it at least gets you going in the right direction.
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell