Hi all,

Some time ago, I suggested implementing something similar to Django's
template context processors, making it possible to create template
variables that are present across all templates
(https://github.com/ChicagoBoss/ChicagoBoss/pull/180).

Now, I've had some time to think about this, and given CB's way of
automatically deferring the purpose of modules from where they reside, I
kind of feel that this approach is better for template context
processors, too. The idea is that if you put a module into
src/view/lib/template_context_modules and export funs with a given
arity, these funs will be called by the template rendering machinery and
their return values will be injected into the templates as variables one
can use at one's own leisure. See 
https://github.com/fdevibe/ChicagoBoss/commit/edf4110ec669a220670471794b0c007d80f60e08

Now, this got me thinking about whether the existing variables,
_session, _req, _base_url and _before (and _lang) couldn't also be
included in the same way. Why handle these differently? So I took the
idea a bit further and made a default context processing module for
these variables (_lang is more involved, so I left that one alone).
Then, one can turn off or modify these variables in templates should one
wish to. See
https://github.com/fdevibe/ChicagoBoss/commit/dab5c6698cde3e12d8d85e2808d952a39156a4dd

Admittedly, this second commit constitutes a larger change, and would
require one to copy the default file into existing applications (once)
upon a CB upgrade. I still feel that this is a natural step given the
first one.

So, I hope somebody has viewpoints on these approaches. Is it a good
idea to allow users to inject app-wide template variables, and if so, is
this a viable approach? Second, given a positive answer to the previous
questions, does it make sense to modify existing behaviour and move
currently injected variables to the application side? Of course, this
still needs to go into a pull request that would require acceptance. ;-)

Thanks for any input!


- Fredrik

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/ygnmvbw81843.fsf%40rubin.ifi.uio.no.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to