Jinja2TT2 (early-stage) Jinja2 → Template Toolkit 2 (Perl) transpiler #2131
lucianofedericopereira
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I’ve built an experimental transpiler that converts Jinja2 templates into Perl Template Toolkit 2 (TT2). The goal is to help teams that want to reuse existing Jinja2 templates in Perl environments or migrate gradually without rewriting everything by hand.
Repository: https://github.com/lucianofedericopereira/jinja2tt2
Supported Constructs
Variables
{{ foo }} → [% foo %] {{ user.name }} → [% user.name %] {{ items[0] }} → [% items.0 %]Filters
{{ name|upper }} → [% name.upper %] {{ name|lower|trim }} → [% name.lower.trim %] {{ items|join(", ") }} → [% items.join(', ') %] {{ name|default("Guest") }} → [% (name || 'Guest') %]Conditionals
Loops
Blocks and Macros
Comments
{# This is a comment #} → [%# This is a comment %]Whitespace Control
{{- name -}} → [%- name -%] {%- if x -%} → [%- IF x -%]Other Constructs
{% include "file.html" %}→[% INCLUDE file.html %]{% set x = 42 %}→[% x = 42 %]{{ x if cond else y }}→[% (cond ? x : y) %]true/false→1/0Filter Mapping
upper.upperlower.lowertrim.trimfirst.firstlast.lastlength.sizejoin.joinreverse.reversesort.sortescape/e| html_entitydefault||operatorreplace.replaceSome filters require TT2 plugins (e.g.,
tojsonneedsTemplate::Plugin::JSON).Loop Variable Mapping
loop.indexloop.countloop.index0loop.indexloop.firstloop.firstloop.lastloop.lastloop.lengthloop.sizeLimitations
{% extends %}) requires manual adjustment for TT2'sWRAPPERpatternThis is still an early-stage project, so any guidance or suggestions are welcome.
Thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions