We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35843
    • 34 Posts
    Hey

    Kind of new to modx snippets so bear with me.

    I'm trying to take a template variable named image_file and i'm trying to just output a message and display if it's there and if not then output an error.

    Here is my snippet code named: image_snippet

    <?php
    $output = "";
    $tv_value = $modx->getTemplateVar(array('image_file'),$docid='4');
    
    if (!empty($tv_value['image_file']))
    {
        $output = '<img src="'.$tv_value['image_file'].'" />';
    }
    else
    {
       echo 'Nothing To Show';
    }
    
    return $output;
    ?>


    This is the code in my template:
    {{html_header}}
    [*content*]
    [[image_snippet]]
    {{html_footer}}
    


    I understand if else constructs and all that however I don't know why I can't get any output with tv_value;

    Any help would be appreciated, been at this for days.

    Thanks
    Riz

      • 3109 ☆ A M B ☆
      • 894 Posts
      It seems your over complicating things for yourself when you can use output modifiers with the TV instead.

      Something like this:

      
      [[*teamplateVariableName:!empty=`<img src="[[*templateVariableName]]" />`:else=`Nothing to display`]]
      
      


      This should work unless you're trying to do something else.

      Hope that helps.
        Benjamin Marte
        Interactive Media Developer
        Follow Me on Twitter | Visit my site | Learn MODX
        • 35843
        • 34 Posts
        tried that code but it didn't work. I'm using evo, is there a different type of syntax for it. Also is phx built in to evo or does it need to be installed directly. i did both and neither worked.

        thanks
          • 22427
          • 793 Posts
          phx has to be installed. Then this should do it:
          [+phx:if=`[*image_file*]`:isnot=``:then=`<img src="[*image_file*]" />`:else=`Nothing to display`+]
            • 3109 ☆ A M B ☆
            • 894 Posts
            Sorry about that didn't know you were talking about evo.
              Benjamin Marte
              Interactive Media Developer
              Follow Me on Twitter | Visit my site | Learn MODX
              • 4041
              • 788 Posts
              Looks like your issue is a spelling error:
              replace this:
              $modx->getTemplateVar

              with this:
              $modx->getTemplateVarOutput
                xforum
                http://frsbuilders.net (under construction) forum for evolution