From 1cd996cbc7e913a85bad3bc5dba00a6e0630a12f Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 12 Nov 2019 17:36:50 +0300 Subject: [PATCH] feat(core): add json_encode and json_decode twig filter #289 --- flextype/twig/JsonTwigExtension.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/flextype/twig/JsonTwigExtension.php b/flextype/twig/JsonTwigExtension.php index 0eee281f..e934d19d 100644 --- a/flextype/twig/JsonTwigExtension.php +++ b/flextype/twig/JsonTwigExtension.php @@ -11,6 +11,7 @@ namespace Flextype; use Twig_Extension; use Twig_SimpleFunction; +use Twig_SimpleFilter; class JsonTwigExtension extends Twig_Extension { @@ -40,6 +41,19 @@ class JsonTwigExtension extends Twig_Extension ]; } + /** + * Returns a list of filters to add to the existing list. + * + * @return array + */ + public function getFilters() : array + { + return [ + new Twig_SimpleFilter('json_decode', [$this, 'decode']), + new Twig_SimpleFilter('json_encode', [$this, 'encode']), + ]; + } + /** * Encode JSON */