Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a Phoenix "Layout"?

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"?

like image 533
Eric S. Bullington Avatar asked Sep 20 '15 16:09

Eric S. Bullington


1 Answers

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

like image 160
José Valim Avatar answered Nov 09 '22 21:11

José Valim