Blog Sections Open

Using Snippet Output as a TV Parameter in Evolution CMS

A practical pattern for using snippet output inside TV-driven rendering without turning the whole template into an unreadable chain of nested tags.

Sometimes a TV does not hold the final value you want to render. Instead it holds a document ID, a selector, or another intermediate value that has to be transformed by a snippet before it is useful in the frontend.

The source discussion described a TV that stored a value later used by Ditto:

[[Ditto? &documents=`[*position*]` &display=`1` &tpl=`price-tpl`]]

The next question was whether a snippet result could be inserted into the TV-driven parameter chain. In practice, yes.

Two common approaches

  • Call the snippet directly where the parameter is used.
  • Evaluate the snippet result first and store the derived value in a placeholder or TV.

Example with runSnippet

@EVAL return $modx->runSnippet('snippetName');

This works, but it should be used carefully. If the snippet is heavy or called many times inside listings, performance can degrade quickly.

A better rule of thumb

If the snippet output is stable for the duration of the request, compute it once and pass the result forward. If it truly depends on each current row or TV value, keep the call close to the place where the final parameter is assembled.

What to avoid

  • Nesting multiple snippet calls directly inside TV bindings when one precomputed placeholder would do.
  • Using @EVAL for logic that should really live in a named snippet or plugin.
  • Hiding important transformation logic in a place editors cannot reason about later.

The pattern is valid, but clarity matters. The more complex the value derivation becomes, the more it belongs in explicit PHP logic rather than in deeply nested inline tag expressions.

Newer post

Using the IF Snippet When Output Contains a Colon

How to write IF snippet conditions safely when the output text itself contains a colon and should not be parsed as part of the condition expression.

Older post

Using @SELECT TVs While Keeping Empty Values at the Top

How to prepend an empty option to an @SELECT TV binding without losing sorted output from the actual query results.