API Function Definition
Variable name: evalSnippet
CMS versions: 0.9.x + Evo
Input parameters:
Return if successful: Output of a given snippet
Return Type: string
Return on failure: empty string (or false?)
Object parent:


Description / Usage

string evalSnippet(string $snippet [, array $params]);

Executes the snippet code contained in $snippet. For running a snippet by calling its name, see runSnippet.

Related functions

Function Source

File: manager/includes/document.parser.class.inc.php

function evalSnippet($snippet, $params) {
$etomite = $modx = &$this;

$modx->event->params = & $params; // store params inside event object
if (is_array($params)) {
extract($params, EXTR_SKIP);
$snip = eval ($snippet);
$msg = ob_get_contents();
if ($msg && isset($php_errormsg)) {
if (!strpos($php_errormsg, 'Deprecated')) { // ignore php5 strict errors
// log error
$this->logEvent(1, 3, "<b>$php_errormsg</b><br /><br /> $msg", $this->currentSnippet . " - Snippet");
if ($this->isBackend())
$this->Event->alert("An error occurred while loading. Please see the event log for more information<p />$msg");
return $msg . $snip;

Suggest an edit to this page.