Provides many extension tag

v1.3 2024-04-19 09:46 UTC

This package is auto-updated.

Last update: 2024-05-19 10:03:42 UTC


README

Provides a {% switch %} tag for Twig switch case statements.
Provides a {% includeDir %} tag for Twig
Provides a {% useDir %} tag for Twig

1. switch

Usage

{% switch myVar %}
    {% case 'value1' %}
        {# ...code here to run for value1 #}
    {% case 'value2' %}
        {# ...code here to run for value2 #}
    {% default %}
        {# ...code here to run for default when no case matched #}
{% endswitch %}

2. includeDir

Usage

{% includeDir '/popups' %}

The files in the directory will be included alphabetically.

Recursive usage

To include all files within a given directory recursive simply add the keyword recursive to your include statement:

<div class="modal-container">
    {% includeDir '/popups' recursive %}
</div>

Now also the popups from the directories /popups/user and /popups/system etc. will be included.

Caution: The templates will be included alphabetically as well, including the directories. Thus the template /popups/footer.twig will be included before the templates from the directory /popups/system followed by /popups/user followed by a possible /popups/zebraHeader.twig. It is recommended to use includeDir only for templates which do not require a specific order.

Variables

As known from the Twig Core include you can control the available variables with the keywords with and only (compare: include)

<div class="modal-container">
    {# only the foo variable will be accessible #}
    {% includeDir '/modals' recursive with {'foo': 'bar'} only %}
</div>

2. useDir

Usage

{% useDir '/form/specials' %}

The files in the directory will be included alphabetically.

Recursive usage

To use all files within a given directory recursive simply add the keyword recursive to your use statement:

{% useDir '/form/specials' recursive %}

Now also the popups from the directories /form/specials and /form/field etc. will be used.

Caution: The templates will be used alphabetically as well, including the directories. Thus the template /form/field/select.twig will be included before the templates from the directory form/specials. It is recommended to use useDir only for templates which do not require a specific order.