Snippet List
Tags like `url` and `trans` provide no way to get the result as a context variable. But how would you get a computed URL into a `blocktrans`?
This snippet solves the general problem. Just put the template code whose output you want to capture within `captureas` tags. For example:
{% captureas login_url %}{% url login %}{% endcaptureas %}
{% blocktrans %}
<a href="{{login_url}}">login</a>
{%endblocktrans%}
- template
- variable
- assign
- capture
- blocktrans
Sometimes you want to create a temporal variable to store something or do anything you want with it, problem is that django template system doesn't provide this kind of feature. This template tag is just for that.
Syntax::
{% assign [name] [value] %}
This will create a context variable named [name] with a value of [value]
[name] can be any identifier and [value] can be anything. If [value] is a callable, it will be called first and the returning result will be assigned to [name]. [value] can even be filtered.
Example::
{% assign count 0 %}
{% assign str "an string" %}
{% assign number 10 %}
{% assign list entry.get_related %}
{% assign other_str "another"|capfirst %}
{% ifequal count 0 %}
...
{% endifequal %}
{% ifequal str "an string" %}
...
{% endifequal %}
{% if list %}
{% for item in list %}
...
{% endfor %}
{% endif %}
2 snippets posted so far.