jmf/twig-type

Twig extension for testing variables type (integer, string, class, etc).

1.0.0 2024-06-05 14:40 UTC

This package is auto-updated.

Last update: 2024-09-05 15:20:06 UTC


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 %}