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

    I have a list of TVs that use the Image Widget - giving the user a choice of six images that can be added to a template. These images then use PHP thumb to resize.

    However sometimes there might only be 2 or 4 images uploaded, therefore on the rendered HTML I only want those output. Currently they are output regardless if the TV has no image.

    From my understanding the image widget should not display a TV if it is blank/no value. See here: http://modxcms.com/forums/index.php/topic,2940.0.html

    This is the sample template call:

    <li><a href="#"><img src="[*imageone:phpthumb=`&w=100&h=100`*]" alt="Example of our work" /></a></li>
    <li><a href="#"><img src="[*imagetwo:phpthumb=`&w=100&h=100`*]" alt="Example of our work" /></a></li>
    <li><a href="#"><img src="[*imagethree:phpthumb=`&w=100&h=100`*]" alt="Example of our work" /></a></li>
    <li><a href="#"><img src="[*imagefour:phpthumb=`&w=100&h=100`*]" alt="Example of our work" /></a></li>
    <li><a href="#"><img src="[*imagefive:phpthumb=`&w=100&h=100`*]" alt="Example of our work" /></a></li>
    <li><a href="#"><img src="[*imagesix:phpthumb=`&w=100&h=100`*]" alt="Example of our work" /></a></li>

    Any idea how to programmatically hide those TV’s from output final HTML if they have no value?

    EDIT: Solved it myself.

    If you are interested here is the call now:

    [*imageone:len:gt=`0`:then=`{{imageone}}`:else=``*]
    [*imagetwo:len:gt=`0`:then=`{{imagetwo}}`:else=``*]
    [*imagethree:len:gt=`0`:then=`{{imagethree}}`:else=``*]
    [*imagefour:len:gt=`0`:then=`{{imagefour}}`:else=``*]
    [*imagefive:len:gt=`0`:then=`{{imagefive}}`:else=``*]
    [*imagesix:len:gt=`0`:then=`{{imagesix}}`:else=``*]

    Have a chunk for each image, for instance:

    <li><a href="#"><img src="[*imageone:phpthumb=`&w=100&h=100`*]" alt="Example of our work" /></a></li>

    Works perfectly smiley