I would like to create new variable in django template, which will have a value of comparison
obj.site.profile.default_role == obj
Unfortunately none of this code works:
{% with obj.site.profile.default_role==obj as default %}{% endwith %}{% with default=obj.site.profile.default_role==obj %}{% endwith %}
What is the proper syntax?
with
can take just a "plain" context variable.
You could try assignment-tags instead, passing your params to it.
@register.assignment_tag
def boolean_tag(default_role, obj):return default_role == obj
and in the template
{% boolean_tag obj.site.profile.default_role obj as my_check %}
This solution is good if variable is used in one template block (like the case of yours, when you try using with
). If you need variable in several page blocks, adding it to page context with include
tag is better