views:

37

answers:

2

To the risk of being closed as duplicate (I can't really find it...) I have the following question. I am sure it's either under my nose, or not possible, but I prefer to ask.

Is it possible to bind to multiple, shorter variable names in django? I know the existence of with, but with assumes you open a block. I would like to bind three or four, meaning that I would have to open (and close) four with blocks. Feasible, but not very nice.

Example, say I have this in my context: foo.bar.baz.quux1, foo.bar.baz.quux2, foo.bar.baz.quux3. I would like to bind them to quux1, quux2 and quux3 for easier access.

A: 

{% with foo.bar.baz.quux3 as quux3 %}

uswaretech
-1 - Read the question before answering: "Is it possible to bind to *multiple*, shorter variable names in django? I know the existence of `with`..."
Dominic Rodger
+3  A: 

No, there isn't a built-in way. You could do this in the view, or write a shortcut method on foo. Alternatively a custom template tag could do it.

Daniel Roseman