Braces.HTML (Braces v0.1.0)

Copy Markdown View Source

Templates in any language rendered as safe HTML for Phoenix, such as a stored email template previewed in a LiveView. Only defined when phoenix_live_view is installed.

Values are escaped as the template's language escapes them, and the result is written as HTML, escaped once:

{Braces.HTML.render!(@template, @data)}

<Braces.HTML.render template={@email.body} language={:liquid} data={@recipient} />

Summary

Functions

A function component that renders a template in any language in HEEx.

Renders a compiled template in any language as Braces.render!/3 does, as safe HTML: {:safe, iodata}.

Functions

render(assigns)

A function component that renders a template in any language in HEEx.

Attributes

  • template (:any) (required) - A compiled template in any language, from its module's compile/2 or its sigil, or source, compiled on each render, in the language given.

  • language (:atom) - The language of template when it's source, such as :liquid, or :mustache. Defaults to nil.

  • data (:any) - The data, as Braces.render/3 takes it. Defaults to %{}.

  • opts (:list) - Options for the language's render/3, such as templates: or helpers:. Defaults to [].

Slots

  • error - Rendered with the error when the template doesn't compile or can't be rendered. Without it, the error is raised.

render!(template, data, opts \\ [])

Renders a compiled template in any language as Braces.render!/3 does, as safe HTML: {:safe, iodata}.