public function TwigExtension::phpFilter in Twig Tweak 8.2
Same name and namespace in other branches
- 8 src/TwigExtension.php \Drupal\twig_tweak\TwigExtension::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/
TwigExtension.php, line 1334
Class
- TwigExtension
- Twig extension with some useful functions and filters.
Namespace
Drupal\twig_tweakCode
public function phpFilter(array $context, $code) {
// Make Twig variables available in PHP code.
extract($context, EXTR_SKIP);
ob_start();
// phpcs:ignore Drupal.Functions.DiscouragedFunctions.Discouraged
print eval($code);
$output = ob_get_contents();
ob_end_clean();
return $output;
}