Skip to content

Instantly share code, notes, and snippets.

@Gregg
Created February 11, 2011 04:41
Show Gist options
  • Save Gregg/821930 to your computer and use it in GitHub Desktop.
Save Gregg/821930 to your computer and use it in GitHub Desktop.
<!-- 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