5

In the Elixir IRC, josevalim refers to a way to compose templates in Phoenix, by defining and then using a layout helper, as such:

<%= with_layout Layout, "app..." do %>hello<% end %>

I'm very new to Phoenix, but I'm assuming the with_layout helper is defined in the view corresponding to the template above, but I can't figure out where/how to define and/or access this Layout. I'm familiar now with "templates" and "views", but can't find much info on Phoenix layouts or layout helpers.

So my question is, what exactly does Layout refer to here, and how do Phoenix "layouts" differ from "templates"?

Eric S. Bullington
  • 1,001
  • 1
  • 11
  • 18

1 Answers1

8

That conversation is very old by Phoenix standards. I don't think it is valid anymore, not even I know what it means. ;)

If you want to render something with a layout, you just need to call in your views:

render(YourApp.UserView, "index.html",
       layout: {YourApp.LayoutView, "app.html"})

The LayoutView is the one Phoenix generates by default in your apps. You can read more about this in Phoenix docs: http://hexdocs.pm/phoenix/Phoenix.View.html#render/3

José Valim
  • 50,409
  • 12
  • 130
  • 115
  • Ah perfect, that answers my question on how to emulate traditional template inheritance, looks like it's totally possible and easy to do. Don't know how I missed that section on the LayoutView in the docs, think I spent too much time browsing the guide (which is excellent) and not enough in the API docs (also excellent). Thank you for your help! – Eric S. Bullington Sep 20 '15 at 19:53