pyjade icon indicating copy to clipboard operation
pyjade copied to clipboard

Django context vars not being passed in ternary expressions

Open valeriansaliou opened this issue 10 years ago • 1 comments

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.

valeriansaliou avatar Mar 05 '14 11:03 valeriansaliou

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 ;)

valeriansaliou avatar Mar 05 '14 11:03 valeriansaliou