evalSnippet

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:

API:evalSnippet

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);
}
ob_start();
$snip = eval ($snippet);
$msg = ob_get_contents();
ob_end_clean();
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");
}
}
unset($modx->event->params);
return $msg . $snip;
}

Suggest an edit to this page.