A view engine for rendering EEx templates. Complete demo application is in "demo" subfolder
If available in Hex, the package can be installed
by adding eex_render to your list of dependencies in mix.exs:
def deps do
[
{:eex_render, "~> 0.1"},
]
enddefmodule Demo do
use Plug.Router
use EExRender,
templates: ["lib/template/"],
layout: "layout",
helpers: [Helpers]
get "/" do
conn
|> render("home")
end
end- All files
*.html.eexinlib/templatewill be precompiled to EEx templates. layout.html.eexis set as default layout, therefore it must exists and contain<%= @main_content %>- All functions in
Helpersmodule will be available in templates
This way render("home") will render home.html.eex inside layout.html.eex and send as HTML response
Other usages:
render(conn, html: "<b>html</b>")send HTML fragment (without layout)render(conn, json: %{a: 1, b: "json"})send JSONrender(conn, text: "OK")send text/plainrender(conn, text: "Not Found", status: 404, content_type: "vnd/error)custom status/content_type