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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access