mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.6k stars 641 forks source link

items with jinja2 compatibility on #699

Open shaunpatterson opened 8 years ago

shaunpatterson commented 8 years ago

I have a json object with:

{
   items: [...]
}

However, I have jinja2 compatibility on (which I'll have to evaluate if I can turn off..).

{% for item in myobject.items %}

Is returning the function items()

{% for item in myobject.['items'] %}

does the same

Is there some way of accessing items without turning off Jinja2 compat?

carljm commented 8 years ago

I'm afraid that currently you're stuck; you either need to turn off jinja compat, or name the attribute something other than items.

I'd be open to proposals for how to change this behavior in the jinja compat layer. If we were aiming for even better compatibility with Jinja, we'd copy the behavior described in the "Implementation" callout box here: http://jinja.pocoo.org/docs/dev/templates/#variables That is, we'd have .foo and ['foo'] perform slightly different lookups, where in the former case the method would be returned and in the latter case the data member would be.

I'll accept this ticket as a feature request for that behavior; PR welcome!