Question

I'm using Mako's inheritance features to factor out common page elements, like a header and footer, into a "base.mako" template. Page-specific controllers use their own templates, which inherit base.mako.

base.mako needs a set of variables -- for example, the name of the logged-on user goes in the header for all pages. However, it's the individual page controller that selects and renders the template, and is therefore responsible for passing variables to it.

I'd rather all of those page controllers not have to know what the base template needs in its context. What's a good way to establish the context for the base template in a situation like this?

Thanks in advance!

Was it helpful?

Solution

You have two OO design choices for your page controllers.

Common features can be handled two ways.

  • Inheritance. All page controllers are subclasses of a common class that provides the common attributes.

  • Delegation. All page controllers are part of a pipeline where some common process (either before or after the page controller) folds in the additional information.

You have to pick one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top