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

Let {{.}} be current item when checking for existance #185

Closed
devth opened this issue Mar 14, 2012 · 3 comments
Closed

Let {{.}} be current item when checking for existance #185

devth opened this issue Mar 14, 2012 · 3 comments

Comments

@devth
Copy link

devth commented Mar 14, 2012

Mustache.render("{{#name}}hello {{.}}{{/name}}!", {name: "foo"})

Outputs: "hello [object Object]!"

Expected: "hello foo!"

Not sure if this is by design. The scalate mustache implementation renders this as expected.

@pg1671
Copy link

pg1671 commented Apr 5, 2012

This would be very helpful when trying to render values that may be a list or a single item.

I have a template that renders images ... sometimes the images urls are in a list and sometimes it is just a single image url. The same template is used to render photos (many) and logo's (1) .. hence the list and the single image in different contexts.

I have a section for images and then a value containing either a list or a single url depending on the context.
{{#image}}
{{#value}}
<img src="{{.}}" .....
{{/value}}
{{/image}}

This works fine for lists but . context does not seem to be set for single items.

For now I will just convert single images to a list but this would be nice unless there is a reason for it to work this way.

@flyx
Copy link

flyx commented Nov 11, 2013

Current workaround: use the name of the value again:

Mustache.render("{{#name}}hello {{name}}{{/name}}!", {name: "foo"})

Be aware that this will not work anymore when this issue gets fixed.

@mjackson
Copy link
Contributor

The 0.7 branch supports this behavior for objects, but not for plain strings. This has been added in the 0.8 branch which should be released soon.

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

4 participants