4👍
✅
The problem is simply with your syntax in the code you posted:
{{l.code=="es"|yesno:"disabled,"}}
It’s actually processed like:
{{ l.code=={{"es"|yesno:"disabled,"}} }}
(Note: that code doesn’t work, it’s just meant to illustrate how Django reads it)
What you want is a custom template tag that works like the if
templatetag but returns like the yesno
filter. You could search around on something like djangosnippets.com; maybe someone has already done the work for you. Otherwise, I’d suggest looking at the Django source code for those two and try to merge them into your own templatetag.
0👍
Or you could use jQuery/javascript to set the class:
http://api.jquery.com/attr/
something like this – not tested!
{% get_language_info for LANGUAGE_CODE as l %}
<script>
{% if l.code='es' %}
$('.english').attr('class','disable');
{% else %}
$('.english').attr('class','disable');
{% endif %}
</script>
<a href="/path/to/switch/to/spanish"
id="spanish" class='enable">
<img src="/spanish/flag/url" alt="Spanish" >
</a>
<a href="/path/to/switch/to/english"
id="english" class='enable">
<img src="/english/flag/url" alt="English">
</a>
- [Django]-Getting a "bound method" error with my login form
- [Django]-JQuery: if statement to select an option value
- [Django]-Format numbers in Django with Intcomma
Source:stackexchange.com