youlead-bow / twig
Provides many extension tag
Requires
- php: >=8.1
- twig/twig: ^3.12
Requires (Dev)
- phpunit/phpunit: ^7.0 || ^8.0 || ^9.0
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.