Last updated Mar 1st, 2021 | Page history | Improve this page | Report an issue
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.
$292 per month—let's make that $500!Learn more
What is the @EVAL Binding?¶
The @EVAL Binding executes the specified PHP code. It should be used with careful security precautions.
Simply put a PHP statement after the @EVAL tag:
@EVAL return "The time stamp is now ".time();
@EVAL $a = 'dog'; return $a;
Showing Related Posts¶
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:
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'=>'||'));
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.