views:

28

answers:

1

This is rather a general question about MVC.

I have a set of templates for multiple controllers and their actions. All of them inherit from a overall template that contains footer/header.

I want header to render email of currently logged in user. Common task.

All tutorials are too simple to have basic example of how and where do I pass common data for all controller actions (set of actions).

Do I need to modify BaseController to add data to tmpl_context? Or create another class like BaseControllerForActionsWithHeaderData that has _before_ method that sets tmpl_context.email... ?

+1  A: 

If you need any of these variables, in principle, for each controller in your application, probably a good idea is to put them in the __before__ method of BaseController. If you need them only in few controllers you should probably create a separate class for it. Another option is to use decorators for each method...

Never in the documentation did not came across a suggestion how to do it in "pylons-style", but i don't think that is very important and you should choose the most convenient and "clean" way for you.

Maciej Kucharz