views:

74

answers:

1

In which cases is it better to create template tags (and load them into the template), than creating a context processor (which fills the request automatically)?

e.g. I have a dynamic menu that has to be included into all templates, so I'm putting it into my base.html. What is the preferred usage: context processor or custom template tag? And why?

+2  A: 

Context processors is for putting data (information, content, objects) into the context used to render page.

Template tags are for formatting or processing that content.

A template tag that makes up new data is confusing. Not impossible or wrong, but very confusing.

S.Lott
not necessarily in my opinion: {% load advertisementtags %}{% get_top_ads as myads %} {% for ad in myads %}...{% endfor %}that's the way with template tags. with a context processor, I could put "myads" into the context as well. That's why I was asking for "best practices" stuff.Maybe it's just a matter of taste.
mawimawi
@mawimawi: It's not a matter of taste. "Advertisement tags" *should* come from a context processor -- they're content. Technically, *anything* is possible, including really hard-to-understand things. it's simpler if content comes from context.
S.Lott