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

Interpolation when the key mirrors a built-in str method #117

Open
tdy opened this issue Jan 21, 2023 · 1 comment · May be fixed by #118
Open

Interpolation when the key mirrors a built-in str method #117

tdy opened this issue Jan 21, 2023 · 1 comment · May be fixed by #118

Comments

@tdy
Copy link

tdy commented Jan 21, 2023

If the mustache key mirrors a built-in str method (e.g., title), chevron doesn't interpolate the conditional value:

args = {
    'template': '{{#title}}{{title}}{{/title}}',
    'data': {'title': 'foo'},
}
chevron.render(**args)

# '<built-in method title of str object at 0x7f5007b6d430>'

Is this expected or a bug?

Currently I'm using a lambda workaround, but not sure if I'm missing something obvious:

args = {
    'template': '{{#title}}{{title}}{{/title}}',
    'data': {'title': lambda x, render: render(x, {'title': 'foo'})},
}
chevron.render(**args)

# foo

(chevron version 0.14.0)

@echuber2
Copy link

echuber2 commented Jan 21, 2023

Another workaround:

>>> chevron.render('{{#title}}{{title}}{{/title}}', {'title': {'title':'bob'}})
'bob'

As further evidence that this shouldn't be the expected behavior in Chevron, note the inconsistency otherwise:

>>> chevron.render('{{#title}}{{title}}{{/title}}', {'title': 'bob'})
'<built-in method title of str object at 0x7efd4d6bfe70>'
>>> chevron.render('{{#foo}}{{foo}}{{/foo}}', {'foo': 'bob'})
'bob'

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

Successfully merging a pull request may close this issue.

2 participants