public static function TwigTweakExtension::phpFilter in Twig Tweak 3.1.x
Same name and namespace in other branches
- 3.x src/TwigTweakExtension.php \Drupal\twig_tweak\TwigTweakExtension::phpFilter()
Evaluates a string of PHP code.
Parameters
array $context: Twig context.
string $code: Valid PHP code to be evaluated.
Return value
mixed The eval() result.
File
- src/
TwigTweakExtension.php, line 667
Class
- TwigTweakExtension
- Twig extension with some useful functions and filters.
Namespace
Drupal\twig_tweakCode
public static function phpFilter(array $context, string $code) {
// Make Twig variables available in PHP code.
extract($context);
ob_start();
// phpcs:ignore Drupal.Functions.DiscouragedFunctions.Discouraged
print eval($code);
$output = ob_get_contents();
ob_end_clean();
return $output;
}