Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List rendering does not work with view objects #59

Open
bugadani opened this issue Sep 17, 2019 · 1 comment
Open

List rendering does not work with view objects #59

bugadani opened this issue Sep 17, 2019 · 1 comment

Comments

@bugadani
Copy link

bugadani commented Sep 17, 2019

I'm trying to use chevron in my project, where I was previously using pystache. Pystache was really flexible in what I could pass to it, and it would treat anything as a list, that can be iterated on. While changing to chevron, however, I found that I have to wrap a lot of stuff with list(), mostly dict .keys()/.values() views.

Minimal repro from pyhon console:

import chevron

ctx = {'template': '{{#list}}{{.}}{{/list}}', 'data':{'list': {'foo': 'bar', 'baz': 'foobar'}.values()}}
chevron.render(**ctx)
"dict_values(['bar', 'foobar'])"

ctx = {'template': '{{#list}}{{.}}{{/list}}', 'data':{'list': list({'foo': 'bar', 'baz': 'foobar'}.values())}}
chevron.render(**ctx)
'barfoobar'

I'm using Python 3.7.3

@oschettler
Copy link

oschettler commented Jul 2, 2021

List rendering does not seem to work at all (at least in Python 3.9.5):

import chevron
import pystache

data = {
    'members': [
        { 'name': 'M1' },
        { 'name': 'M2' },
        { 'name': 'M3' },
    ]
}

tmpl = '''
{{ #members }}
 - {{ name }}
{{ /members }}
'''

print('PyStache', pystache.render(tmpl, data))
print('Chevron', chevron.render(tmpl, data))

This results in

PyStache 
 - M1
 - M2
 - M3

Chevron 

 - 

The PyStache output is what I would expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants