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