jmf / twig-type
Twig extension for testing variables type (integer, string, class, etc).
1.0.1
2026-05-31 00:32 UTC
Requires
- php: ^8.3
- twig/twig: ^3.0
Requires (Dev)
- overtrue/phplint: ^9
- phpstan/phpstan: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^12|^13
- rector/rector: ^2
- squizlabs/php_codesniffer: ^4
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 %}