Dynamo.HTTP.Render

Conveniences for template rendering. To use them, just import this module.

Source

Functions summary

render(conn, template, assigns \\ [])

Renders a template and assigns its contents to the connection response body and content type. If the connection is in streaming mode, the template is streamed after it is rendered as a whole chunk.

Functions

render(conn, template, assigns \\ [])

Renders a template and assigns its contents to the connection response body and content type. If the connection is in streaming mode, the template is streamed after it is rendered as a whole chunk.

Besides the connection and the template name, this function also receives extra assigns as arguments. Assigns are used by the developer to pass information from the router to the template.

It raises Dynamo.TemplateNotFound if the given template can't be found.

Examples

# Renders the template usually at web/templates/hello.html
render conn, "hello.html"

# Assign to data (accessible as @data in the template)
conn = conn.assign(:data, "Sample")
render conn, "hello.html"

# Same as before, but does not assign to the connection
render conn, "hello.html", data: "Sample"

Layouts

Rendering also supports layouts. The layout name should be given as an assign. After the template is found, a layout with the same format will be looked up and rendered if available.

It is common to set a layout that is used throughout the dynamo in your ApplicationRouter and it will be carried out to all other routers:

prepare do
  conn.assign :layout, "application"
end
Source