We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38670
    • 11 Posts
    Hi, i'm trying to show the content of a TV in some ditto results, only if the Template Variable exists. I've tryed some options but anyone gave me any result. This is the last code I tried in a snippet:

    <?php
    $myVar = $modx->getTemplateVarOutput(array('tvname'));
    echo $myVar['tvname'];
    ?>
    


    Let's say that the Template Variable name is "tvname"... And when I use this snippet, it doesn't return anything (And i'm sure that the TV has content).

    I'm thinking that the problem is that i'm trying to use this in the results of a ditto and as $myVar appears many times, it crashes.

    Any suggestion?

    Thanks!
      • 21417
      • 486 Posts
      Hi elmaguire,

      Have you tried PHx?
      http://modx.com/extras/package/phx


      I am not a coder by any stretch of the imagination so cannot comment on your snippet code but I find PHx really handy in these instances - that's how I would tackle "the content of a TV in some ditto results, only if the Template Variable exists".

      Putting the following in your ditto template might work:
      [+phx:if=`[+tvname+]`:is=``:then=``:else=`[+tvname+]`+]


      Good luck.
        Web design Adelaide
        http://gocreate.com.au
        • 36416
        • 589 Posts
        Yes, use "notempty" family of custom modifiers:
        http://wiki.modxcms.com/index.php/PHx/CustomModifiers#phx:ifnotempty


        If you need logic based on resource template, you can also try:
        [+template:is=`11`:then=`...`+]
          • 38670
          • 11 Posts
          Thanks for the help!