rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

How to add "elseif" for twig #117

Closed hansemschnokeloch closed 3 months ago

hansemschnokeloch commented 4 months ago

Hi,

I'm using djhtml to format twig files. It works very well except for elseif that is used by twig instead of elif in jinja2

How can I modify djhtml in order to recognize elseif as elif ?

Adding elif in twig was discussed here https://github.com/twigphp/Twig/issues/1282

JaapJoris commented 3 months ago

If you search the code for the string "elif", you will find this list of "closing and opening tags":

    CLOSING_AND_OPENING_TAGS = [
        "elif",
        "else",
        "empty",
        "plural",
    ]

If you want your fork to support Twig's {% elseif %} statement, you can add it to this list. It won't be merged into mainline DjHTML though, because it (currently) only supports Django and Jinja syntaxes, which both use {% elif %}.