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

Copy Markdown View Source

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

# config/config.exs
config :phoenix_template, :template_engines, mustache: Braces.Mustache.Phoenix.Engine

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

The file is parsed when your module compiles, so a template that doesn't parse raises a CompileError at its line. It renders as Braces.Mustache.render/3 renders it: a missing value renders nothing, as Mustache says. There are no partials.

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