Reputation: 61
I'm looking to have two different footers, and have one appear on specific pages. The site has a lot of pages, so I don't want to just hardcode each footer into each page.
In rails, how can I put in logic to have which footer appears on which page? Is there an 'if' statement I can put directly on the _footer partial that displays the footer by page?
Thanks in advance for your help!
Upvotes: 1
Views: 396
Reputation: 171
You can crate two different layouts( add .erb file to direcroty layouts in views ) or can create two partial and use them when you want, for example:
In your Controller add
class Controller
...
# You may use class or instrance variable
def your_method
# your logic...
@footer_variable = true
end
in your layout file add
<%= if @footer_variable %>
<%= render 'optional_footer' %>
<%= else %>
<%= render 'footer' %>
<%= end %>
and add to your layout's directory file footer.html.erb with your normal footer and optional_footer.html.erb
Optional Footer
<div>
<span>I'm your optional footer</span>
</div>
Normal Footer
<div>
<span>I'm your normal footer</span>
</div>``
If instance variable will be availiable in layout it will ber rendered optional footer otherwise normal footer( from your layout )
Upvotes: 1
Reputation: 4593
Your going to want to have two different layouts. If you show me some of your code i will be about to help you out a little more.
Upvotes: 1