We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36931
    • 206 Posts
    Dear All

    I know how to check if a TV is empty of not
    [[*image-1:ifnotempty=`not empty`]]


    My problem, I have serveral TV and if all of them are empty, I do not want to display a div

    [[*image-1:ifnotempty=`<div>Hello</div>`]]
    [[*image-2:ifnotempty=`<div>Hello</div>`]]
    [[*image-3:ifnotempty=`<div>Hello</div>`]]
    [[*image-4:ifnotempty=`<div>Hello</div>`]]
    [[*image-5:ifnotempty=`<div>Hello</div>`]]
    [[*image-6:ifnotempty=`<div>Hello</div>`]]
    


    I do not know how to modify the above code to display only
    <div>Hello</div>

    if at least on of the TV is not empty.

    I need to have something like this
    if (*image-1:ifnotempty OR *image-2:ifnotempty OR *image-2:ifnotempty ...){
       then display : <div>Hello</div>
    }
    


    Do see?
    Thank
      • 4172
      • 5,888 Posts
      sounds like a MIGX-TV could be the better solution to add as many images as you like to your resources.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 38290
        • 712 Posts
        Sounds like a good use case for a snippet with your custom logic
          jpdevries
          • 3749
          • 24,544 Posts
          I'm not positive what you're trying to do, but this might be it. It will depend on how the TVs are set up. You'll only need one tag.

          [[!ShowImages]]




          <?php
          /* ShowImages snippet */
          $output = '';
          
          $tvs = array(
              'image-1',
              'image-2',
              /* etc. */
          );
          
          foreach ($tvs as $tv) {
             $image = $modx->resource->getTVValue($tv);
          
             if (! empty($image)) {
                $output .= "\n" . '<div>' . $image . '</div>';
             }
          }
          
          return $output;
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting