-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_6.html.erb
41 lines (31 loc) · 2.03 KB
/
tutorial_6.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
34
35
36
37
38
39
40
41
<h1>Fire.app Feature Tutorial</h1>
<h2>Changing the Content of Layouts for Particular Pages (Advanced)</h2>
<p>In the current project, all the pages have the same sidebar except the homepage. But, in the example file we've seen previously, the "Document" page's <code><div class="ad"></code> block in the sidebar shows education contact information but not "Ad Words". So, we need to use the helper, <code>content_for</code>, and you can check details in <a href="template_helper.html">Template Helpers</a>.</p>
<p>To complete this, we need to change the single page's sidebar. But, because we already put the sidebar in our common layout, we need to change <code><div class="ad"></code> in <code>_layout.html.erb</code>. Let's find this part:</p>
<pre class="prettyprint linenums lang-html">
<div class="ad">
Ad Words
</div>
</pre>
<p>And modify it to:</p>
<pre class="prettyprint linenums lang-html">
<div class="ad">
<% if content_for? :sp_ad %>
<%= yield :sp_ad %>
<% else %>
Ad Words
<% end %>
</div>
</pre>
<p>The code above sets <code><div class="ad"></code> to display <code>Ad Words</code> by default. But when the identifier <code>:sp_ad</code> is already storing a block using <code>content_for :sp_ad</code>, the stored content will be displayed.</p>
<p>So, let's add this segment at the front of the "Document" page <code>documents.html.erb</code>: </p>
<pre class="prettyprint linenums lang-html">
<% content_for :sp_ad do %>
If you need education support, please mail to:<br />
<a href="#"><%= lorem_email %></a>
<% end %>
</pre>
<p>In the code above, we set the content of <code>:sp_ad</code> in the "Document" page. So if you switch to your browser, you'll see the "Document" page's sidebar shows the education contact information.</p>
<div class="page-footer">
Next: <a href="tutorial_7.html">Making an Extended Layout Based-on an Existing Layout (Advanced) <i class="lsf-icon arrow"></i></a>
</div>