NAME

jinja2tt2 - Transpile Jinja2 templates to Template Toolkit 2

SYNOPSIS

jinja2tt2 [options] [input_file]

# From file
jinja2tt2 template.j2 > template.tt

# From stdin
echo '{{ name|upper }}' | jinja2tt2

# In-place conversion
jinja2tt2 -i template.j2

# With debug output
jinja2tt2 -d template.j2

OPTIONS

-h, --help

Print this help message and exit.

-v, --version

Print version information and exit.

-d, --debug

Print debug information (tokens and AST) to stderr.

-o, --output FILE

Write output to FILE instead of stdout.

-i, --inplace

Convert file in place, creating a .tt file alongside the input.

EXAMPLES

# Simple variable
echo '{{ user.name }}' | jinja2tt2
# Output: [% user.name %]

# Filter
echo '{{ name|upper }}' | jinja2tt2
# Output: [% name.upper %]

# Loop
echo '{% for item in items %}{{ item }}{% endfor %}' | jinja2tt2
# Output: [% FOREACH item IN items %][% item %][% END %]

# Conditional
echo '{% if user %}Hello{% endif %}' | jinja2tt2
# Output: [% IF user %]Hello[% END %]

SUPPORTED CONSTRUCTS

  • Variables and attribute access

  • Filters (most common ones)

  • for loops (including else clause)

  • if/elif/else conditionals

  • Blocks and inheritance (partial)

  • Includes

  • Macros

  • Comments

  • Whitespace control (-% tags)

LIMITATIONS

  • Template inheritance (extends) requires manual adjustment

  • Some filters need TT2 plugins (JSON, Dumper, etc.)

  • Complex expressions may need review

  • Autoescape is not directly supported in TT2

AUTHOR

Luciano Federico Pereira