Fire.app Feature Tutorial
Changing the Content of Layouts for Particular Pages (Advanced)
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 <div class="ad">
block in the sidebar shows education contact information but not "Ad Words". So, we need to use the helper, content_for
, and you can check details in Template Helpers.
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 <div class="ad">
in _layout.html.erb
. Let's find this part:
<div class="ad"> Ad Words </div>
And modify it to:
<div class="ad"> <% if content_for? :sp_ad %> <%= yield :sp_ad %> <% else %> Ad Words <% end %> </div>
The code above sets <div class="ad">
to display Ad Words
by default. But when the identifier :sp_ad
is already storing a block using content_for :sp_ad
, the stored content will be displayed.
So, let's add this segment at the front of the "Document" page documents.html.erb
:
<% content_for :sp_ad do %> If you need education support, please mail to:<br /> <a href="#"><%= lorem_email %></a> <% end %>
In the code above, we set the content of :sp_ad
in the "Document" page. So if you switch to your browser, you'll see the "Document" page's sidebar shows the education contact information.