jmf / twig-type
Twig extension for testing variables type (integer, string, class, etc).
1.0.0
2024-06-05 14:40 UTC
Requires
- php: >=8.3
- twig/twig: ^3.0
Requires (Dev)
- phing/phing: ^2.17
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.1
- rector/rector: ^1.0
- squizlabs/php_codesniffer: ^3.8
README
Installation & Requirements
Install with Composer:
composer require jmf/twig-type
Usage in Twig templates
get_class() filter
Returns class of provided object.
{% set class = object|get_class %}
get_type() filter
Returns type of provided variable.
{% set type = value|get_type %}
"array" test
Returns true if provided variable is an array.
{% if (value is array) %} {# ... #} {% endif %}
"bool" (boolean) test
Returns true if provided variable is a boolean.
{% if (value is bool) %} {# ... #} {% endif %}
"float" test
Returns true if provided variable is a float.
{% if (value is float) %} {# ... #} {% endif %}
"int" (integer) test
Returns true if provided variable is an integer.
{% if (value is int) %} {# ... #} {% endif %}
"numeric" test
Returns true if provided variable is numeric.
{% if (value is numeric) %} {# ... #} {% endif %}
"object" test
Returns true if provided variable is an object.
{% if (value is object) %} {# ... #} {% endif %}
"scalar" test
Returns true if provided variable is scalar.
{% if (value is scalar) %} {# ... #} {% endif %}
"string" test
Returns true if provided variable is a string.
{% if (value is string) %} {# ... #} {% endif %}