[[[[*TVname:isequalto=`<li></li>` &then=`` &else=`$categoryChunk`]]]]
[[!ShowMyTv]]
/* ShowMyTV snippet */
$tv = $modx->resource->getTVValue('MyTV');
if (empty($tv)) {
return '';
}
$tvArray = explode(",", $tv);
$output = '<ul class="whatever">';
foreach($tvArray as $item) {
$output .= "\n <li>" . $item . "</li>";
}
$output .= "\n</ul>"
return $output;
You could leave it as you had it but rather than testing for empty, test for whatever is in the TV when it's empty (do a "View Source" to see what's there). Something like this:
[[[[*TVname:isequalto=`<li></li>` &then=`` &else=`$categoryChunk`]]]]
A custom snippet, though, is always much faster, you can make it straight text TV and use comma delimiters, then process it any way you want in the snippet. Here's an example:
[[!ShowMyTv]]
/* ShowMyTV snippet */ $tv = $modx->resource->getTVValue('MyTV'); if (empty($tv)) { return ''; } $tvArray = explode(",", $tv); $output = '<ul class="whatever">'; foreach($tvArray as $item) { $output .= "\n <li>" . $item . </li> } $output .= "\n</ul>" return $output;
/* ShowFeatures snippet Display Interior Features */
$tv = $modx->resource->getTVValue('propFeature_Interior');
if (empty($tv)) {
return '';
}
$tvArray = explode(",", $tv);
$output = '<h5>Interior</h5><ul class="no-bullet">';
foreach($tvArray as $item) {
$output .= "\n <li>" . $item . </li>
}
$output .= "\n</ul>"
return $output;
<?php
/* ShowFeatures snippet Display Interior Features */
$tv = $modx->resource->getTVValue('propFeature_Interior');
if (empty($tv)) {
return '';
}
$tvArray = explode(",", $tv);
$output = '<h5>Interior</h5><ul class="no-bullet">';
foreach($tvArray as $item) {
$output .= "\n <li>" . $item . "</li>";
}
$output .= "\n</ul>";
return $output;
I do notice that you and Susan put your brackets on the very outer edges, but the docs have them tucked around each TV or Chunk. Are the docs wrong, or are there just multiple ways of writing it out?
<?php
/* Snippet to Display Number of Fireplaces */
$tv = $modx->resource->getTVValue('fireplaceQty');
if (empty($tv)) {
return '';
}
$output = '<li><smalllabel>FIREPLACE:</smalllabel> [[*fireplaceQty]]</li>';
return $output;<?php
/* Snippet to Display Number of Fireplaces */
$tvname = $modx->getOption('tvname', $scriptProperties, '');
$tpl = $modx->getOption('tpl', $scriptProperties, '');
$output = '';
if (!empty($tvname) && !empty($tpl)) {
$tv = $modx->resource->getTVValue($tvname);
if (!empty($tv)) {
$output = str_replace('[[+value]]', $tv, $tpl);
}
}
return $output;&tvname=`fireplaceQty` &tpl=`<li><smalllabel>FIREPLACE:</smalllabel>[[+value]] </li>`