Git Product home page Git Product logo

twig's Introduction

Twig extensions

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.

twig's People

Contributors

flavou45 avatar youlead-bow avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.