View Source Mjml (mjml v3.1.0)
Provides functions for transpiling MJML email templates to HTML.
Summary
Functions
Converts an MJML string to HTML content.
Functions
Converts an MJML string to HTML content.
Returns a result tuple:
{:ok, html}
for a successful MJML transpiling{:error, message}
for a failed MJML transpiling
You can pass render options to customize the rendering of the final HTML:
keep_comments
– whenfalse
, removes the comments from the rendered HTML. Defaults totrue
.social_icon_path
– when given, uses this base path to generate social icon URLs. E.g.social_icon_path: "https://example.com/icons/"
will generate a social icon URL, like "https://example.com/icons/github.png"fonts
– a Map of font names and their URLs to hosted CSS files. When given, includes these fonts in the rendered HTML (Note that only actually used fonts will show up!). Defaults tonil
, which will make the default font families available to be used (Open Sans, Droid Sans, Lato, Roboto, and Ubuntu).
Examples
iex> Mjml.to_html("<mjml><mj-head></mj-head></mjml>")
{:ok, "<!doctype html><html xmlns=..."}
iex> Mjml.to_html("something not MJML")
{:error, "Couldn't convert MJML template"}
iex> opts = [
iex> keep_comments: false,
iex> social_icon_path: "https://example.com/icons/"
iex> fonts: %{
iex> "Noto Color Emoji": "https://fonts.googleapis.com/css?family=Noto+Color+Emoji:400"
iex> }
iex> ]
iex> Mjml.to_html("<mjml><mj-head></mj-head></mjml>", opts)
{:ok, "<!doctype html><html xmlns=..."}