Skip to content

Commit

Permalink
Add the evaluate Twig function
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Oct 13, 2015
1 parent 3f2d9b4 commit 00ec536
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions system/src/Grav/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function getFunctions()
new \Twig_simpleFunction('t', [$this, 'translate']),
new \Twig_simpleFunction('ta', [$this, 'translateArray']),
new \Twig_SimpleFunction('url', [$this, 'urlFunc']),
new \Twig_SimpleFunction('evaluate', [$this, 'evaluateFunc']),
];
}

Expand Down Expand Up @@ -450,6 +451,19 @@ public function urlFunc($input, $domain = false)
return $resource ? rtrim($uri->rootUrl($domain), '/') . '/' . $resource : null;
}

/**
* Evaluate a string
*
* @example {{ evaluate('grav.language.getLanguage') }}
*
* @param string $input String to be evaluated
* @return string Returns the evaluated string
*/
public function evaluateFunc($input)
{
return $this->grav['twig']->processString("{{ $input }}");
}

/**
* Based on Twig_Extension_Debug / twig_var_dump
* (c) 2011 Fabien Potencier
Expand Down

0 comments on commit 00ec536

Please sign in to comment.