syrusakbary / pyjade

Jade template system for Django, Jinja2 and Mako
MIT License
699 stars 122 forks source link

How to use variables in templatetags? #282

Closed good-idea closed 7 years ago

good-idea commented 7 years ago

Specifically, I'm trying to supply a dynamic argument to Django's template fragment caching templatetag:

{% load cache %}
{% cache 500 sidebar request.user.username %}
    .. sidebar for logged in user ..
{% endcache %}

I've tried all of the methods of interpolation here, but it always ends up taking the whole thing literally. For example:

- cache sidebar {{request.user.username}}
// u('template.cache.{{request.user.username}}.d41d7c....
- cache sidebar #{request.user.username}
// u('template.cache.#{request.user.username}.d41d7c....

Is it possible to include variables here? Is this a simple Jade thing that I'm missing, an issue with Django, or pyjade?

good-idea commented 7 years ago

Closing this, nevermind -- - cache sidebar request.user.username works as expected: you just don't see the username in the cache tab of the Django toolbar.