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.
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>