Jump to main content Jump to doc navigation
Note: The @EVAL binding has been deprecated and removed in MODX 3.0.

What is the @EVAL Binding?

The @EVAL Binding executes the specified PHP code. It should be used with careful security precautions.

Syntax

@EVAL php_code_here

Usage

Simply put a PHP statement after the @EVAL tag:

@EVAL return "The time stamp is now ".time();
@EVAL $a = 'dog'; return $a;

Examples

There's a whole page showing an example of using the EVAL binding to execute a snippet: Creating a multi-select box for related pages in your template.

db-driven input-option-values by using rowboat

Let's say we want to have a dropdown-box to select a user-id by username. Requirements: The rowboat-snippet.

First, we create a new chunk for our Options and name it 'userOption' with this code:

[[+username]]==[[+id]]

Then create a dropdown-type TV with this input-options:

@EVAL return '-- choose a user --||' . $modx->runSnippet('Rowboat',array('table'=>'modx_users','tpl'=>'userOption','outputSeparator'=>'||'));

Security

The use of eval() is a security sensitive binding and should be used with caution. For this reason it has also been removed in 3.0 and can be disabled sooner with the allow_tv_eval system setting.

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Digital Penguin
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • Following Sea
  • Anton Tarasov
  • eydolan
  • Raffy
  • Lefthandmedia
  • Murray Wood
  • Snow Creative
  • Nick Clark
  • Helen
  • JT Skaggs
  • krisznet
  • YJ
  • Yanni
  • Richard

Budget

$366 per month—let's make that $500!

Learn more