views:

11

answers:

0

Background

In many of the websites I work on, there's a header/footer/menu that is created from data from the model layer. This piece is present on every page of the site. Usually, it's part of the "layout", whatever that means for whatever framework I'm using at the time

An example of this would be a list of categories in the page footer that link to lists of all the items in that category. Usually, they'll have the number of items in that category next to the link and be sorted alphabetically.

Question

Where should the code go that retrieves this list of categories, sorts it, prepares it, etc? If the page in question was the "List of categories" page, then I would put it in the controller and be done with it. The fact that it's the same for all pages/controllers makes me think there's a better way to do it?

Possible Ideas

  • Have all of the controllers extend from an application-specific controller that looks up the categories and automatically adds it to the view.
  • Develop view first so a common piece of code is inherently used to render the common bits.
  • A template tag that is able to contain model/controller code.

I realize that answers may be framework-specific, but maybe we'll hit upon a best practice anyway.