Changes between Version 7 and Version 8 of TemplatePitfalls
- Timestamp:
- Sep 14, 2005, 7:12:34 AM (19 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TemplatePitfalls
v7 v8 35 35 If your needs are middling simple, or you don't want to have to write your own custom template tag from scratch, I've developed a generic option: [http://www.deadlybloodyserious.com/categories/django/2005/09/06.html vars], which defines a fairly generic {{{pushvars}}} tag that calls the function of your choice and pushes its results into the current context. 36 36 37 I'm posting this to atone for my previous crummy advice on this Wiki page. 38 39 {{{- garthk}}} 37 I'm posting this to atone for my previous crummy advice on this Wiki page. {{{- garthk}}} 40 38 41 39 ''But what if your custom template tags needs access to the HttpRequest object in order to do it's stuff? For example, if you have a menu or a breadcrumb that depends on request.path, or on the session etc? Does the DjangoContext object provide access to this in any way? The only ways I've found are things like subclassing DjangoContext and getting that to use the request to create any data needed for the base templates/custom template tags, but that won't work with generic views AFAIK. (I'm happy using my current method, as I haven't actually used generic views yet, but imagine I may need to soon). Cheers.'' 42 40 41 I had a chat to Adrian about that. They haven't yet seen a compelling reason to have {{{DjangoContext}}} stash a copy of {{{request}}}, and indeed it turned out that there was an easy workaround to my use case (access to the request path for my login system). If you have a good use case, submit a ticket. {{{ - garthk }}}