PhoenixKit. Templates. Substitution
(phoenix_kit_templates v0.1.0)
View Source
{{variable}} substitution.
The syntax matches what the database-backed email templates used, so content
exported from those rows carries over unchanged. Surrounding whitespace is
allowed: {{user_email}} and {{ user_email }} are the same placeholder.
Unbound placeholders are left alone
A placeholder with no matching variable is emitted verbatim, not blanked.
Both are wrong, but a visible {{user_emial}} announces the typo in a preview
or a test, while a silent empty string reads as finished copy and ships. The
renderer never raises over one — a message with a flawed placeholder must
still send — so callers that want it to be an error ask missing/2 up front.
Summary
Types
Variables to interpolate. Keys may be atoms or strings.
Functions
Placeholder names in content that variables does not bind.
Replaces every bound placeholder in content.
The placeholder names appearing in content, in order, without duplicates.
Types
Functions
Placeholder names in content that variables does not bind.
Empty means every placeholder will be filled.
iex> PhoenixKit.Templates.Substitution.missing("{{a}} {{b}}", %{a: 1})
["b"]
Replaces every bound placeholder in content.
iex> PhoenixKit.Templates.Substitution.substitute("Hi {{name}}", %{name: "Ada"})
"Hi Ada"
iex> PhoenixKit.Templates.Substitution.substitute("Hi {{name}}", %{})
"Hi {{name}}"
The placeholder names appearing in content, in order, without duplicates.
iex> PhoenixKit.Templates.Substitution.variables("Hi {{name}}, {{ name }} again")
["name"]