librelist archives

« back to archive

New features (templates and menus)

New features (templates and menus)

Graham Ashton
2010-12-11 @ 17:01
One of the most frequently asked questions about Nesta is "How do I make a
site like the PeepCode blog?", on which every page has a different design.

My stock answer has always been to suggest that you add your own metadata 
key which controls which stylesheet to use when rendering the page. That 
works, but only gets you so far as you can't use this approach to render 
different HTML on each page.

Now you can; I just added two new options that you can set at the top of 
each page:

  Layout: shop
  Template: product
  Categories: products

  # Buy my Flugelbinders


Docs are here:

And while I'm talking about new stuff, I committed support for Nested 
menus yesterday. Probably best explained with an example. Imagine you'd 
put this in menu.txt:


... this in your app.rb file:

  @menu = Nesta::Menu.full_menu

... and this in your template:

  - display_menu(@menu, :levels => 1)

You'd just get links to home, blog, documentation and about in your menu 
(i.e. primary nav). The :levels setting controls how far down the menu 
tree it goes when rendering <ul> and <li> tags, so for primary nav 1 is a 
good bet.

Or you could get secondary nav for a section, by asking for a menu beneath
a specific part of the tree:

  # in app.rb
  first_part_of_path = request.path.split('/')[1]  # e.g. 'docs'
  @menu = Nesta::Menu.for_path(first_part_of_path)

  # in your template
  - display_menu(@menu, :levels => 3)

I've not written any docs for this yet, but hopefully you get the idea. 
There's a new Menu class in lib/models.rb, and the view helper is in the 
default app.rb file.

Here are the relevant patches:

Now it's time for the gem...