diff --git a/CHANGELOG.md b/CHANGELOG.md index a3804fe..3bc5f95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Twig Perversion Changelog +## 2.2.0 - 2020.12.07 +### Added +- Added `is array` test + ## 2.1.0 - 2019.06.09 ### Added - Added `{% while %}` loop. diff --git a/README.md b/README.md index 074e820..7d31d01 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Making twig do things it really shouldn't. Twig is not intended to be a gene - `{% while %}`, `{% break %}`, `{% continue %}`, and `{% return %}` tags - `===`, `!==`, and `<=>` operators -- `is numeric` and `is string` tests +- `is numeric`, `is string`, and `is array` tests - `array_splice`, `string`, `float`, `int`, and `bool` filters ## Requirements @@ -121,6 +121,18 @@ or {{ 12 is string ? 'Yes' : 'No' }} {# No #} +{``` + +- **Array** + + Test whether given value is an array. + +```Twig +{ [] is array ? 'Yes' : 'No' }} +{# Yes #} + +{{ '12' is array ? 'Yes' : 'No' }} +{# No #} ``` diff --git a/composer.json b/composer.json index 2459667..6e873d2 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "marionnewlevant/twig-perversion", "description": "Making twig do things it really shouldn't", - "version": "2.1.0", + "version": "2.2.0", "type": "craft-plugin", "keywords": [ "craft", "craftcms", "plugin", "twigperversion" diff --git a/src/twigextensions/Array_Test.php b/src/twigextensions/Array_Test.php new file mode 100644 index 0000000..da4d1fe --- /dev/null +++ b/src/twigextensions/Array_Test.php @@ -0,0 +1,10 @@ +raw('is_array(')->subcompile($this->getNode('node'))->raw(')'); + } +} diff --git a/src/twigextensions/TwigPerversionTwigExtension.php b/src/twigextensions/TwigPerversionTwigExtension.php index 19bb62e..9c7a072 100644 --- a/src/twigextensions/TwigPerversionTwigExtension.php +++ b/src/twigextensions/TwigPerversionTwigExtension.php @@ -46,6 +46,7 @@ public function getTests() return [ new \Twig_Test('numeric', null, ['node_class' => '\marionnewlevant\twigperversion\twigextensions\Numeric_Test']), new \Twig_Test('string', null, ['node_class' => '\marionnewlevant\twigperversion\twigextensions\String_Test']), + new \Twig_Test('array', null, ['node_class' => '\marionnewlevant\twigperversion\twigextensions\Array_Test']), ]; }