Created
October 13, 2016 15:42
-
-
Save pbmarcano/395cea9727f70542150cb89df4a5d945 to your computer and use it in GitHub Desktop.
Nested layouts in Rails
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<%= render 'layouts/head' %> | |
</head> | |
<body> | |
<%= render 'layouts/navigation' %> | |
<div class="container"> | |
<%= yield %> | |
</div> | |
<%= render 'layouts/footer' %> | |
</body> | |
</html> |
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
module ApplicationHelper | |
#.... | |
def extends(layout, &block) | |
# Make sure it's a string | |
layout = layout.to_s | |
# If there's no directory component, presume a plain layout name | |
layout = "layouts/#{layout}" unless layout.include?('/') | |
# Capture the content to be placed inside the extended layout | |
@view_flow.get(:layout).replace capture(&block) | |
render file: layout | |
end | |
#.... | |
end |
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
<%= extends :application do %> | |
<%# additional HTML... %> | |
<%= yield %> | |
<%# additional HTML... %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment