j2templify is a minimal, fast, and flexible CLI tool written in Rust that renders Jinja2-style templates using YAML configuration files.
It supports variable overrides, whitespace cleanup, autoescaping, and portable deployment (including musl-based static builds). Ideal for configuration file generation, Dockerfile templating, and CI/CD workflows.
- 🧠 Simple CLI: Just
--templateand--vars - 🎯 Supports nested YAML structures
- 🔄 Command-line variable overrides via
--set key=value - 🧼 Optional blank-line cleanup with
--clean-newlines - 🔒 Optional autoescaping with
--enable-autoescape - 🧳 Easy cross-compilation with
muslfor Linux portability
Clone the project and build with Rust:
git clone https://github.com/your-username/j2templify.git
cd j2templify
cargo build --releaseTo install the binary globally (optional):
sudo cp target/release/j2templify /usr/local/bin/For static musl binary (fully portable Linux build):
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-muslj2templify -t template.j2 -v config.yamlj2templify -t template.j2 -v config.yaml -o output.txtj2templify -t template.j2 -v config.yaml \
--set os=alinux \
--set alinux.base_image='"alinux3:dev"'Note: Values passed to
--setare parsed as YAML, so use "..." for strings.
j2templify -t template.j2 -v config.yaml --clean-newlinesj2templify -t template.j2 -v config.yaml --enable-autoescapeAutoescaping is disabled by default. Use this flag to enable it for safer HTML or XML output.
Dockerfile.j2:
# syntax=docker/dockerfile:1
{% if os == "alinux" %}
FROM {{ alinux.base_image }}
{% else %}
FROM {{ ubuntu.base_image }}
{% endif %}config.yaml:
os: "ubuntu"
alinux:
base_image: "alinux3:latest"
ubuntu:
base_image: "ubuntu:22.04"To run with test files during development:
cargo run -- -t Dockerfile.j2 -v config.yaml --clean-newlinesTo run with CLI overrides:
cargo run -- -t Dockerfile.j2 -v config.yaml \
--set os=alinux \
--set alinux.base_image='"alinux3:preview"'To test with autoescaping enabled:
cargo run -- -t template.j2 -v config.yaml --enable-autoescapeInspired by Jinja2, tera, and jintemplify. Built for real-world template generation needs, with control over output and flexibility for automation pipelines.