Module ActionView::Partials
[quote]Partials can have their own layouts applied to them. These layouts are different than the ones that are specified globally
for the entire action, but they work in a similar fashion. Imagine a list with two types of users:
<!-- app/views/users/index.html.erb -->
Here's the administrator:
[code] <%= render :partial => "user", :layout => "administrator", :locals => { :user => administrator } %>[/code]
Here's the editor:
[code] <%= render :partial => "user", :layout => "editor", :locals => { :user => editor } %>[/code]
<!-- app/views/users/_user.html.erb -->
[code] Name: <%= user.name %>[/code]
<!-- app/views/users/_administrator.html.erb -->
[code] <div id="administrator">
Budget: $<%= user.budget %>
<%= yield %>
</div>[/code]
<!-- app/views/users/_editor.html.erb -->
[code] <div id="editor">
Deadline: $<%= user.deadline %>
<%= yield %>
</div>[/code]
...this will return:
Here's the administrator:
[code] <div id="administrator">
Budget: $<%= user.budget %>
Name: <%= user.name %>
</div>[/code]
Here's the editor:
[code] <div id="editor">
Deadline: $<%= user.deadline %>
Name: <%= user.name %>
</div>
[/code]
You can also apply a layout to a block within any template:
<!-- app/views/users/_chief.html.erb -->
[code] <% render(:layout => "administrator", :locals => { :user => chief }) do %>
Title: <%= chief.title %>
<% end %>[/code]
...this will return:
[code] <div id="administrator">
Budget: $<%= user.budget %>
Title: <%= chief.name %>
</div>[/code][/quote]
[quote]Partials can have their own layouts applied to them. These layouts are different than the ones that are specified globally
for the entire action, but they work in a similar fashion. Imagine a list with two types of users:
<!-- app/views/users/index.html.erb -->
Here's the administrator:
[code] <%= render :partial => "user", :layout => "administrator", :locals => { :user => administrator } %>[/code]
Here's the editor:
[code] <%= render :partial => "user", :layout => "editor", :locals => { :user => editor } %>[/code]
<!-- app/views/users/_user.html.erb -->
[code] Name: <%= user.name %>[/code]
<!-- app/views/users/_administrator.html.erb -->
[code] <div id="administrator">
Budget: $<%= user.budget %>
<%= yield %>
</div>[/code]
<!-- app/views/users/_editor.html.erb -->
[code] <div id="editor">
Deadline: $<%= user.deadline %>
<%= yield %>
</div>[/code]
...this will return:
Here's the administrator:
[code] <div id="administrator">
Budget: $<%= user.budget %>
Name: <%= user.name %>
</div>[/code]
Here's the editor:
[code] <div id="editor">
Deadline: $<%= user.deadline %>
Name: <%= user.name %>
</div>
[/code]
You can also apply a layout to a block within any template:
<!-- app/views/users/_chief.html.erb -->
[code] <% render(:layout => "administrator", :locals => { :user => chief }) do %>
Title: <%= chief.title %>
<% end %>[/code]
...this will return:
[code] <div id="administrator">
Budget: $<%= user.budget %>
Title: <%= chief.name %>
</div>[/code][/quote]