Reputation: 75
I try to make a month calendar view with python/Django. Is it possible to set variables in {% %} segments?
I want to have it like this:
The top month names are generated when a new month starts. Is something like this possible?
{% if entry.month == lastmonth %}
// show month name
{% lastmonth = entry.month %}
And this in a for structure?
Upvotes: 1
Views: 129
Reputation: 1687
You can use the {% with %}
template tag to set variables inside templates. See here for details: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#with
In your case, you can do something like this:
{% for item in collection %}
{% if item-satisfies-condition %}
{% with variable=some-value %}
stuffs...
{% endwith %}
{% endif %}
{% endfor %}
Upvotes: 3