pyjade
pyjade copied to clipboard
Django context vars not being passed in ternary expressions
Hello,
I noticed that, although Django context variables could be accessed from Jade templates, they remain inaccessible from the ternary expressions.
Here's an example:
// 1. This won't work because 'notification.count_new' is being accessed from ternary
.notifications(class=('active' if notification.count_new else ''))
span.number {{ notification.count_new|default:0 }}
// 2. Though this works fine
h1
notification.count_new
Django outputs for 1:
'dict' object has no attribute 'count_new'
Sounds like a bug, uh? Also, Jade template processing should not fail when a variable is not defined or a dict key not existing, it should silently ignore the error as Django built-in template engine does. This makes development much easier by avoiding checking if the variable is defined before using it.
Well, using notification['count_new'] in ternary works, I assume this is me mixing up Pythonic and Jade syntax. Consider this as a bug or not ;)