A small, dependency-free template engine written entirely in Bash inspired by Jinja/Twig.
Copy template into your project or clone the repository.
{{ expression }} Output
{% statement %} Control statement
{# comment #} Template comment{% if variable %}
{% elif variable %}
{% else %}
{% endif %}
{% if [[ "$user" == "Max" ]] %}
{% elif [ "$user" = "Jo" ] %}
{% elif (( 2 + 2 == 4 )) %}
{% for user in users %}
{% endfor %}
{% raw %}
{% endraw %}{{ user }}
{{ users[0] }}
{{ user | tr 'a-z' 'A-Z' }}you can do:
{{ use | rm -rf / }}so templates must be trusted code.
{{ loop.index }}
{{ loop.index0 }}
{{ loop.revindex }}
{{ loop.revindex0 }}
{{ loop.first }}
{{ loop.last }}
{{ loop.length }}
{{ loop.parent.XYZ }}suppresses the newline and whitespaces after or before the tag (or both)
{{ user -}}
{% if enabled -%}
{# comment -#}
{{- user }}
{%- if enabled %}
{#- comment #}suppresses the only whitespaces after or before the tag (or both)
{{ user ~}}
{% if enabled ~%}
{# comment ~#}
{{~ user }}
{%~ if enabled %}
{#~ comment #}source ./template
template file.tmplOr:
./template file.tmplTemplates are trusted code.
Conditions and pipes execute Bash commands.
{% set x="OK" %}
{{ user.name }} for associative arrays
{% break %} and {% continue %} in for loop
{{ user | default("gast") }} or a similar feature for default valueRun test with:
docker run -it -v "$PWD:/code" bats/bats:latest /code/testContributions are welcome! Please open an issue or submit a pull request with any enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for more information.