"variable substitution" ({{ somevar }}
) syntax is indeed not supported in templatetags arguments - which makes sense if you consider that in the context of template rendering, this syntax would be the equivalent of a "print" statement.
This doesn't mean you can't pass context variables to templatetags - else templatetags would be of very limited use - but you do so by just mentionning them ie assuming you have a context variable named "path", you could use it here as
{% if request.path==path %}
...
You can also use filter expressions here, ie this is valid too:
{% if request.path==path|lower %}
(assuming the templatetag's author correctly handled the tags arguments - I let you refer to the documentation for more on this).
Now wrt/ your problem here, you could of course use a custom filter to join the different parts but that would actually be a very bad idea. Django's url handing is based on the idea that you should actually never hardcode an url anywhere - you define and name urls in your urls.py
files, and then use the builtin functions (django.core.urlresolvers.reverse()
) / templatetags ({% url %}
) to generate them.
Here, the proper solution would be to define a get_absolute_url()
method on your sub_cat
object that returns the correct url (actually the path portion of it) for this object, and test against it in the template.
As far as I'm concerned, I'd even use a second indirection level as a template filter so 1/ your model (or whatever sub_cat
is) knows it's own url, and 2/ the template filter can tell if a given sub_cat
is "active" for the current request.path
so if the spec defining when a sub_cat is "active" is to change you'll only have the template filter function to change instead of having to browse thru all your templates (possibly missing something on the way).