From c0d819b97a4e67b48c19f507c6ff530f603c4b4c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Sun, 18 Oct 2020 20:17:17 +0300 Subject: [PATCH] Fixed `print_r()` in twig --- CHANGELOG.md | 1 + system/src/Grav/Common/Twig/TwigExtension.php | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 494fe368f..ffc466287 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Accessing page with unsupported file extension (jpg, pdf, xsl) will use wrong mime type [#3031](https://github.com/getgrav/grav/issues/3031) * Fixed media crashing on a bad image * Fixed bug in collections where filter `type: false` did not work + * Fixed `print_r()` in twig # v1.7.0-rc.17 ## 10/07/2020 diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index d8122f6a3..695ff4990 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -140,7 +140,7 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface new TwigFilter('array_unique', 'array_unique'), new TwigFilter('basename', 'basename'), new TwigFilter('dirname', 'dirname'), - new TwigFilter('print_r', 'print_r'), + new TwigFilter('print_r', [$this, 'print_r']), new TwigFilter('yaml_encode', [$this, 'yamlEncodeFilter']), new TwigFilter('yaml_decode', [$this, 'yamlDecodeFilter']), new TwigFilter('nicecron', [$this, 'niceCronFilter']), @@ -181,7 +181,7 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface new TwigFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), new TwigFunction('dump', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), new TwigFunction('vardump', [$this, 'vardumpFunc']), - new TwigFunction('print_r', 'print_r'), + new TwigFunction('print_r', [$this, 'print_r']), new TwigFunction('http_response_code', 'http_response_code'), new TwigFunction('evaluate', [$this, 'evaluateStringFunc'], ['needs_context' => true]), new TwigFunction('evaluate_twig', [$this, 'evaluateTwigFunc'], ['needs_context' => true]), @@ -241,6 +241,11 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface ]; } + public function print_r($var) + { + return print_r($var, true); + } + /** * Filters field name by changing dot notation into array notation. *