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

    I was wondering if my problem could be solved in a different way than I’ve done right now.

    I have 8 image TV’s assigned to a template.

    For different reasons I cannot use the Image widget so I call them with an image tag like this:

    <img src="[*image1*]" alt="" />

    When I have documents where I only have 2-3 images the rest show as image tags with an empty source.
    That shouldn’t be a problem and it’s not in Firefox and Safari but in Explorer empty image tags show up as red crosses..

    For now I’ve assigned a "Yes/No" Radio TV called "Is the image active?" to each image and use PHx to only show the image tag if the radio is set to "Yes" and otherwise just show nothing.

    That is: [*active:is=`Yes`:then=`<img src="[*image1*]" alt="" />`:else=``*]

    But I really want to get rid of that radio button....

    So my question is.... Is there a way I can use PHx to show the image tag if there is data in the image TV and show nothing if the image tag is empty?
      • 16183
      • 1,390 Posts
      Hi,

      is this what you are looking for?

      http://modxcms.com/forums/index.php?topic=23132.0

      Hope it helps...

      /k
        • 4310
        • 2,310 Posts
        One option is to create your own snippet/widget for the TV’s.
        <?php
        $TVname = isset($tv)?$tv:'image1';
        if( $TVarray = $modx->getTemplateVarOutput(array($TVname)) ){
        $tvOutput = $TVarray[$TVname];
        if(empty($tvOutput)) return '';
        return '<img src="[*image1*]" alt="" />';
        }
        return '';
        ?>

        Name the snippet "ImageOne", repeat for each TV and replace in your template [*image1*] with [!ImageOne!] etc.
          • 33337
          • 3,975 Posts
          [+phx:if=`[*imageTV*]`:ne=``:then=`<img src="[*imageTV*]" alt="" />`+]


          I have used ne, Not Empty function. If there is no value, nothing outputs.

          Very simple and straight forward. smiley
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 7231
            • 4,205 Posts
            You can also use the isnot=`` to see if it blank.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 1788
              • 1,103 Posts
              [+image:ifnotempty=`<img src="[+image+]">`+]