-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_7.html.erb
33 lines (24 loc) · 2.15 KB
/
tutorial_7.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<h1>Fire.app Feature Tutorial</h1>
<h2>Making an Extended Layout Based-on an Existing Layout (Advanced)</h2>
<p>In the example file we've seen previously, both the "Features List" page and the "Feature Detail" page have a promotion text block. To make sure every page in the <code>features</code> folder contains this block, we need a new layout for these pages. But, if we copy the content of our common layout, there will be more duplicated code. So, we'll solve this by using the render template method and <code>content_for</code>. </p>
<p>First, modify the common layout <code>/_layout.html.erb</code>, add this <code>content_for</code> block below the <code><%= render :partial => "main_menu" %></code>:</p>
<pre class="prettyprint linenums lang-html">
<% if content_for? :feature_slogan %>
<%= yield :feature_slogan %>
<% end %>
</pre>
<p>Because we don't need to display anything by default, there's no need to write the "else" part.</p>
<p>Next, add a new layout file <code>_layout.html.erb</code> in the <code>features</code> folder. Page files use the closest layout file by default, so the page files in the <code>features</code> folder will use the new layout.</p>
<p>The content of <code>/features/_layout.html.erb</code> is:</p>
<pre class="prettyprint linenums lang-html">
<% content_for :feature_slogan do %>
<div class="well">
<h3><%= lorem_sentences 2 %></h3>
</div>
<% end %>
<%= render :template => "/_layout" %>
</pre>
<p>The code above makes a new layout based on our common layout. It uses <code><%= render :template => "/_layout" %></code> to assign the layout <code>/_layout.html.erb</code> for these pages to use. And the <code><% content_for :feature_slogan do %></code> part adds the promotion text block for every page which uses this layout. Switch to your browser and you'll see both the "Features List" page and the "Feature Detail" page now have a promotion text block. </p>
<div class="page-footer">
Next: <a href="tutorial_8.html">Getting Current Page Path and Understanding Its Usage (Advanced) <i class="lsf-icon arrow"></i></a>
</div>