I've been using MODX for sometime now and have recently discovered conditional tags. I can't find any mention of them in the official documentation and only found out about them through this forum. Where did I miss this in the docs?
Additionally, will a simple conditional statement create a noticeable performance hit? I have a number of optional TVs in this template and I'm not sure I want to create a snippet for each one.
Thanks.
[ed. note: hhk222 last edited this post 9 years, 10 months ago.]
You could create your own snippet and run the logic there from the TVs, then output the results as placeholders. That might have less of a hit than calling a bunch of 'If' snippets or conditional output modifiers...
Additionally, will a simple conditional statement create a noticeable performance hit? I have a number of optional TVs in this template and I'm not sure I want to create a snippet for each one.
1. Yes.
2. It's likely that you could do it with a single snippet.
Can you give us more information about what you're trying to do?
As a snippet, it would look like this:
[[!AccordionTitle? &value=`[[*accordion_title]]` ]]
/* AccordianTitle snippet */
$title = $modx->getOption('value', $scriptProperties, '');
if (empty($title)) {
$output = '';
} else {
$output = '
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse1Two">
[[*accordion_title]]
</a>
</h4>
</div>
<div id="collapse1Two" class="accordion-body collapse">
<div class="panel-body">
<p>[[*accordion_content]]</p>
</div>
</div>
</div>
'
}
return $output;
I'm not sure it would work, but if it does, it would be significantly faster.