That's going to be painfully slow compared to a dedicated snippet because of the time spent parsing the conditional and evaluating every condition whether it's required or not. You're also going to want a closing div when the condition is met to keep your design from blowing up. You might try this:
[[!TvCheck? &returnValue=`<div class="someClass">`]]
(Div contents here)
[[!TvCheck? &returnValue=`</div>`]]
<?
/* TvCheck snippet */
$r = $modx->resource;
if ($r->getTVValue('TV1') || $r->getTVValue('TV2') || $r->getTVValue('TV3')) {
return $scriptProperties['returnValue'];
}
return '';
If you put the TV most likely to be not empty first, it will speed things up further, as will using the ID of the TV rather than the name (no quotes if you use the ID).
The code below would be even faster, though maybe not enough to notice. It will only work if you can use the raw value of the TV (i.e., it doesn't need processing).
<?
/* TvCheck snippet */
$docId = $modx->resource->get('id');
$tvId = array( /* Use the actual IDs of the TVs here */
12,
22,
29,
);
foreach ($tvs as $tv) {
$tvr = $modx->getObject('modTemplateVarResource',
array('contentid' => $docId, 'tmplvarid' => $tv);
if ($tvr) {
$value = $tvr->get('value');
} else {
$tvObject = $modx->getObject('modTemplateVar', $tv);
$value = $tvObject? $tvObject->get('default_text') : '';
}
if (!empty($value)) {
return $scriptProperties['returnValue'];
}
}
return '';
[ed. note: BobRay last edited this post 9 years, 9 months ago.]