Layouts

Up to this point, we've seen some examples of templates and how they're used to render responses. However, when the controller calls a view to render a template, that view is not rendered directly; the controller first renders the layout view, which then renders the template itself. This way, we can have a consistent style across the application (such as setting headers and footers), without duplicating them across templates.

However, layouts are regular templates. Everything you've learned for templates is also applied to layouts. The Phoenix generators create an app layout, which in our case is available at apps/elixir_drip_web/lib/elixir_drip_web/templates/layout/ app.html.eex. This layout will be compiled into a function on

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.