diff --git a/system/libs/TwigTypeCastingExtension.php b/system/libs/TwigTypeCastingExtension.php new file mode 100644 index 00000000..8b1203e7 --- /dev/null +++ b/system/libs/TwigTypeCastingExtension.php @@ -0,0 +1,36 @@ + */ + public function getFilters(): array + { + return [ + new TwigFilter('int', function ($value) { + return (int)$value; + }), + new TwigFilter('float', function ($value) { + return (float)$value; + }), + new TwigFilter('string', function ($value) { + return (string)$value; + }), + new TwigFilter('bool', function ($value) { + return (bool)$value; + }), + new TwigFilter('array', function (object $value) { + return (array)$value; + }), + new TwigFilter('object', function (array $value) { + return (object)$value; + }), + ]; + } +} diff --git a/system/twig.php b/system/twig.php index 45f43ef5..d7bc3b79 100644 --- a/system/twig.php +++ b/system/twig.php @@ -24,6 +24,9 @@ if($dev_mode) { } unset($dev_mode); +require LIBS . 'TwigTypeCastingExtension.php'; +$twig->addExtension(new MyAAC\Twig\Extension\TwigTypeCastingExtension()); + $function = new TwigFunction('getStyle', function ($i) { return getStyle($i); });