x_component v0.1.0 X.Template View Source
Extends module with ~X
sigil to compile templates.
use X.Template
Link to this section Summary
Functions
Handles sigil ~X
for the X templates.
It returns Elixir AST which can be injected into the function body
Link to this section Functions
Handles sigil ~X
for the X templates.
It returns Elixir AST which can be injected into the function body:
iex> defmodule Example do
...> use X.Template
...>
...> def render(assigns) do
...> ~X(<div>{{ assigns.message }}</div>)
...> end
...> end
...> Example.render(%{message: "test"})
["<div>", "test", "</div>"]
By default ~X
sigil returns iodata
AST. The s
modifier is used to return string:
iex> use X.Template
...> message = "Test"
...> ~X(<div>{{ message }}</div>)s
"<div>Test</div>"