Blog Sections Open

Using the IF Snippet When Output Contains a Colon

A small IF snippet gotcha in Evolution CMS: keep the condition syntax separate from the text you want to print.

The if snippet is compact, but its syntax can become confusing when the output text contains the same punctuation used inside the condition itself. A common example is a value that should be shown with a leading colon only when the TV is greater than a threshold.

The problematic pattern looked like this:

[[if?is=`[*tv*]:gt:1` &then=`: [*tv*]`]]

At first glance it seems fine, but when developers mix condition syntax and output punctuation too tightly, the expression becomes harder to debug.

A clearer way to think about it

The condition belongs entirely inside is. The leading colon belongs entirely inside the output string. Do not try to make the colon part of the logical expression just because it also appears visually in the final output.

Recommended pattern

[[if?
&is=`[*tv*]:gt:1`
&then=`: [*tv*]`
&else=``
]]

Why formatting helps

Breaking the snippet across multiple lines makes it obvious that the colon in the then branch is plain output text, not part of the operator chain. This becomes even more important when the branches contain commas, colons, or HTML fragments.

General rule

When an Evo conditional starts feeling clever, make it more explicit. Readable conditions and readable output branches are easier to maintain than one dense inline expression, especially in long templates that editors or future developers will revisit months later.

Newer post

Filtering getResources and pdoResources by Tag-Like TV Values

How to filter Evolution CMS resource listings by a TV that stores comma-separated tag-style values, and what to watch for when using LIKE-based matching.

Older post

Using Snippet Output as a TV Parameter in Evolution CMS

How to feed the result of a snippet into a TV or listing parameter when a plain stored value is not enough for the final frontend output.