We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14906
    • 9 Posts
    I’m creating a website for a client with products that have multiple template variables. I’d like to be able to pull those tv’s into an unordered list, so in the template I would have:

    <ul>
    <li>[*tv_1*]</li>
    <li>[*tv_some_other*]</li>
    </ul>

    ...But, right now if one of the products doesn’t have any info entered for the TV, I just end up with a bullet point. I would like to be able to just not have the li for that tv show up if it’s empty for that product. How would I go about doing that?

    Thanks!!! You guys rock.
      • 4172
      • 5,888 Posts
      Try phx. If it is a product-listing with Ditto, phx is included and you can use phx directly.
      Without ditto you need to install the plugin phx before you can use it.
      Then try:

      <ul>
           [*tv_1*:isnot=``:then=`<li>[*tv_1*]</li>`]
           [*tv_some_other:isnot=``:then=`<li>[*tv_some_other*]</li>`*]
      </ul>


      another option is to create a snippet ’imagelister’ for your list:


      <?php
      
      $tvnames = explode(',', $tvnames);
      $output = '';
      
      if (count($tvnames) > 0)
      {
          $imagetvs = $modx->getTemplateVarOutput($tvnames);
          foreach ($tvnames as $tvname)
          {
              $image = $imagetvs[$tvname];
              if (!empty($image))
              {
                  $output .= '<li>'.$image.'</li>';
              }
          }
      }
      return $output;
      
      
      


      and call it:

      <ul>
      [!imagelister? &tvnames=`tv_1,tv_some_other`!]
      </ul>

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!