Seth Allen
Seth Allen

Reputation: 81

Hide nav bar and footer on certain pages

I'm building a website for my new company and want to create a landing page for my product that doesn't have a nav bar or a footer. I want to keep the landing page simple and just focus on the product.

I'm coding in Ruby on Rails. Twitter Bootstrap is what I'm using for styling the nav bar and footer.

My home page and about page have a nav bar and footer, but I don't want my product landing page to have the nav bar and footer.

Any suggestions on how I can hide the nav bar and footer on my landing page, but keep it on my other pages?

Upvotes: 8

Views: 5836

Answers (4)

Fillype Farias
Fillype Farias

Reputation: 660

It's very simple:

    # application.html.erb
    <% unless action_name == "index" %>
       # render the footer partial "_footer.html.erb" file from "shared" folder
       <%= render 'shared/footer' %>
    <% end %>

Upvotes: 7

kr&#246;te
kr&#246;te

Reputation: 106

I had the same problem, and I solved it this way:

#app/views/layouts/application.html.erb
<% unless action_name == "landing" %>
   ... navbar ...
<% end %>

using action_name instead of controller_name.

Upvotes: 2

Richard Peck
Richard Peck

Reputation: 76774

To add to code.prio's answer, you could just use a conditional statement in your application layout (saves the hassle of maintaining two layouts):

#app/views/layouts/application.html.erb
<% unless controller_name == "landing" %>
   ... navbar ...
<% end %>

Not as pretty as the other answer, but works better. If you have more than one layout, it gets annoying having to maintain them both.

Upvotes: 12

Mahabub Islam Prio
Mahabub Islam Prio

Reputation: 1085

Yes , you can do it . One easy way is to use a different layout file for the landing page controller other than the default application.html.erb . In your desired template page write a custom layout name which will hold up the different kinds of specification . Let me give an example ,

class SiteController < ApplicationController
  layout "landing_page"
  ...
end

This will load up a different layout with different view as you want for your site , while the default layout can hold the basic navbar and products for other pages.

Thanks . Hope this one way will solve your problem .

Visit This link for more information . ActionView API Docs

Upvotes: 7

Related Questions