IwaiEngine.jl
Jinja-like template engine for Julia.
IwaiEngine compiles templates to Julia functions. It supports a compact Jinja-style syntax while staying fast enough for server-side rendering workloads.
Features
{{ expr }}expressions{% if %},{% elif %},{% else %},{% end %}{% for x in xs %} ... {% end %}withloop.index,loop.index0,loop.first,loop.last,loop.length{% set name = expr %}{% include "partial.iwai" %}{% extends "base.iwai" %}and{% block name %} ... {% end %}{% autoescape false %} ... {% end %}{# comment #}and{% raw %} ... {% endraw %}- filters such as
upper,lower,trim,length,join,default,escape,safe
Installation
using Pkg
Pkg.add(url = "https://github.com/tepel-chen/IwaiEngine.jl")Quick Start
using IwaiEngine
template = IwaiEngine.parse("""
<ul>
{% for team in teams %}
<li>{{ loop.index }}. {{ team.name }} - {{ team.score }}</li>
{% end %}
</ul>
""")
template((
teams = [
(name = "Jiangsu", score = 43),
(name = "Beijing", score = 27),
],
))"<ul>\n\n <li>1. Jiangsu - 43</li>\n\n <li>2. Beijing - 27</li>\n\n</ul>\n"See the guides for file-backed templates, inheritance, and escaping behavior.