Created
February 11, 2011 04:41
-
-
Save Gregg/821930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Lets assume we have a normal layout --> | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1>Main Layout</h1> | |
<% if flash[:notice] %> | |
<span style="color: green"><%= flash[:notice] %></span> | |
<% end %> | |
<%= yield %> | |
</body> | |
</html> | |
<!-- Sometimes, when loading some controllers controllers, we may want to add a sidebar to this layout --> | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1>Main Layout</h1> | |
<%= yield :sidebar %> | |
<% if flash[:notice] %> | |
<span style="color: green"><%= flash[:notice] %></span> | |
<% end %> | |
<%= yield %> | |
</body> | |
</html> | |
<!-- How do we make this work? First up lets address the controller that needs this sidebar | |
class UsersController < ApplicationController | |
layout 'user' | |
So we're creating a custom layout for this user .. Then in that layout we simply do --> | |
<% content_for :sidebar do %> | |
<div class="sidebar"> | |
Lots o stuff | |
</div> | |
<% end %> | |
<%= render :file => 'layouts/application' %> | |
<!-- That's all there is too it... The content for gets inserted where it should.. in the yield :sidebar --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment