Created
December 24, 2012 17:30
-
-
Save bf4/4370117 to your computer and use it in GitHub Desktop.
Rails template / layout inheritance
This file contains 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
-content_for :title do | |
Child Title | |
The rest of the page goes here |
This file contains 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
- content_for :site_name do | |
= 'Child Layout' | |
- content_for :stylesheet do | |
= stylesheet_link_tag 'child' | |
- content_for :site_header do | |
= render :partial => 'child/header' | |
= render :template => 'layouts/parent_layout' |
This file contains 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 template is inherited by other layouts, like child_layout | |
-# and is customized by the content_for blocks there | |
-# that we handle there (they won't be handled on subsequent calls) | |
-# unless we did something like this there to check if there is a receiving content_for? | |
-# otherwise, in this case, yield to the view | |
-# = content_for?(:stylesheet) ? yield(:stylesheet) : yield | |
-# see http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts | |
!!! Strict | |
%html{:xmlns=>"http://www.w3.org/1999/xhtml",:'xml:lang'=>"en", :lang=>"en", 'xmlns:fb'=>'http://ogp.me/ns/fb#'} | |
%head{:prefix => "fb: http://ogp.me/ns/fb#"} | |
- if content_for?(:title) | |
- title = yield(:title) | |
-else | |
- title = 'Welcome' | |
%title= "#{yield(:site_name)} - #{ title }" | |
= yield(:stylesheet) | |
%body | |
%div#container | |
%div#hd | |
= yield(:site_header) | |
%div#bd | |
%div#main | |
%div.b | |
%div.wrapper | |
-unless notice.blank? | |
%p.notice= notice | |
= yield | |
=yield(:javascript) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment