mirror of
https://github.com/getgrav/grav.git
synced 2026-04-14 00:27:37 +02:00
Add the evaluate Twig function
This commit is contained in:
@@ -89,6 +89,7 @@ class TwigExtension extends \Twig_Extension
|
||||
new \Twig_simpleFunction('t', [$this, 'translate']),
|
||||
new \Twig_simpleFunction('ta', [$this, 'translateArray']),
|
||||
new \Twig_SimpleFunction('url', [$this, 'urlFunc']),
|
||||
new \Twig_SimpleFunction('evaluate', [$this, 'evaluateFunc']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -450,6 +451,19 @@ class TwigExtension extends \Twig_Extension
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user