API:evalSnippet

From MODx Wiki
Jump to: navigation, search
 API Function Definition: 
evalSnippet
Versions 
> 0.9.2
Return Values
Success: Output of a given snippet
Fail: empty string (or false?)
Data Type 
string
Object Hierarchy 
DocumentParser
string evalSnippet(string $snippet [, array $params]);


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

Examples

Related Functions

Function Source

File: manager/includes/document.parser.class.inc.php
Line: 761
  1. function evalSnippet($snippet, $params) {
  2. $etomite = $modx = &$this;
  3.  
  4. $modx->event->params = & $params; // store params inside event object
  5. if (is_array($params)) {
  6. extract($params, EXTR_SKIP);
  7. }
  8. $snip = eval ($snippet);
  9. $msg = ob_get_contents();
  10. if ($msg && isset($php_errormsg)) {
  11. if (!strpos($php_errormsg, 'Deprecated')) { // ignore php5 strict errors
  12. // log error
  13. $this->logEvent(1, 3, "<b>$php_errormsg</b><br /><br /> $msg", $this->currentSnippet . " - Snippet");
  14. if ($this->isBackend())
  15. $this->Event->alert("An error occurred while loading. Please see the event log for more information<p />$msg");
  16. }
  17. }
  18. unset($modx->event->params);
  19. return $msg . $snip;
  20. }

Notes

Personal tools