0

I have a small Sinatra app using haml. I'd like to have a navigation bar on each page that will contain the menu, search, and directional scrolling arrows. Since this will be on every page I assume the layout would be the right place. I cannot find a good example of how to achieve this any where.

Would this be a layout with many conditionals? Class names and links will change depending on what the current page is.

What are the best practices to achieve this and are there any examples?

Chris Valentine
  • 1,557
  • 1
  • 19
  • 36
  • 4
    Maybe this will help you: http://net.tutsplus.com/tutorials/ruby/an-introduction-to-haml-and-sinatra/. The most important thing is to actually start making stuff and you'll see how it goes in the way. – Agis Apr 07 '13 at 16:47
  • Thanks I read this but I didn't see any mentions for conditionals in the layout.haml or other methods best used to conditionally change pieces of the menu/nav bar – Chris Valentine Apr 07 '13 at 17:35
  • The word "conditionals" reminds me of [Phrogz's answer](http://stackoverflow.com/a/4200367/664404). Of course you may use if else conditionals in the layout.haml, too, but this is just poor style. – barerd Apr 07 '13 at 17:52
  • Yes that is what I'm asking. What solution is normally used to achieve that type of navigation/menu bar that is not considered poor style? – Chris Valentine Apr 07 '13 at 18:22
  • your best bet would probably be to generate it dynamically .. Or maybe js it – Ven Apr 07 '13 at 19:03

1 Answers1

0

I believe partials is what I should have been looking for. They seem to insert right where I need them.

Sinatra is a super-lightweight framework. Because of this it doesn’t have the notion of partials built into it. However, a partial, in its simplest form, is nothing more than a call out to render the template as a string and then embed that string into your page.

= haml(:mypartial, :layout => false)

Found at http://steve.dynedge.co.uk/2010/04/14/render-rails-style-partials-in-sinatra/

Chris Valentine
  • 1,557
  • 1
  • 19
  • 36