Django has a feature called template context processors (see
https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATE_CONTEXT_PROCESSORS),
that provides the possibility of adding template variables on a global
scale. This allows for, for instance, providing the request variable
to all templates without having to supply it in all controllers.
In
https://github.com/evanmiller/ChicagoBoss/pull/180, a similar
approach is proposed for CB, but after some debate, the preferred
solution is to provide this feature using controller callbacks akin to
'before_'. Using the name context_ is one suggestion, what about
render_vars_?
To provide equivalent functionality to Django's template context
processors, a way of avoiding duplication across controllers would be
preferable, and in the discussion in the pull request, inheritance is
suggested. I believe this could be a good way to go.
So, does anybody have opinions on this? Use-cases or other issues?
One issue that comes to mind is that if inheritance were to solve the
duplication problem for this _and_ the 'before_' callback, afaict,
erlang does not support multiple inheritance (extending multiple
modules). This means that if one wants to inherit this functionality
as well as 'before_', one would need to put them both in the same
module. Now, controllers as compiled by CB's own compiler, so there
might be more flexibility here than I'm aware of. Opinions?
--
- Fredrik