Ludtwig

GitHub GitHub Workflow Status (branch) GitHub release (latest by date including pre-releases) Crates.io GitHub all releases Crates.io

Linter / Formatter for Twig template files which respects HTML and your time.

Features

Current limitations

Installation

Cargo (rust toolchain)

Run the following cargo command to install or update ludtwig: cargo install ludtwig
You can install cargo here: https://www.rust-lang.org/learn/get-started
If you don't want to install the rust toolchain / cargo you can still use the manual installation below.

Manual

Download the latest release binary for your operating system and put it in your PATH for easy access.

How to use Ludtwig?

After the installation have a look at ludtwig --help for more information. It should be self-explanatory. Also have a look at the default config file if you want to customize the way how ludtwig analyses your files. To create it in your current working directory run ludtwig -C.

Allowed syntax

To prevent the creation of invalid / dirty HTML by Twig ludtwig only allows the Twig syntax in certain places. Without this restriction it wouldn't be possible to parse the combined syntax in a single hierarchical syntax tree. Have a look at the example below to get the general idea where Twig syntax is allowed: twig {% block my_component %} {% set isActive = true %} <div id="my-component" class="my-component {% if isLarge %}large{% endif %}" {{ dataAttribute }}="data" {# Single word attributes don't strictly require quotes #} data-active={{ isActive }} > {% block my_component_inner %} <span id="my-span" {% if isActive %} style="color: red" {% endif %} > hello {{ name }} </span> {% endblock %} </div> {% endblock %}

License

Copyright (c) 2023 Malte Janz
ludtwig is distributed under the terms of the MIT License.
See the LICENSE file for details.

For testing purposes this repository also includes code from the following sources (not included in distributed binary): - Shopware - MIT