Braces.Jinja.Phoenix.Engine (Braces v0.1.0)

Copy Markdown View Source

A Phoenix.Template engine for .jinja files. Only defined when phoenix_template is installed.

# config/config.exs
config :phoenix_template, :template_engines, jinja: Braces.Jinja.Phoenix.Engine

Then embed_templates "emails/*" turns emails/welcome.html.jinja into a welcome/1 function, whose assigns are the template's data: {{ first_name }} reads @first_name.

The file is converted with Braces.Jinja.convert/2 and compiled with your module, with the Braces.Filters helpers, so a template that doesn't convert, or that uses a filter Braces.Filters doesn't have, raises a CompileError. A missing value renders nothing, as in Jinja.

In an HTML format, values are HTML-escaped, except with |safe, and the result is safe HTML that Phoenix doesn't escape again. In other formats, such as welcome.text.jinja, values are written as they are.