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
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Lefthandmedia
  • Murray Wood
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

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

Learn more