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

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

4 participants

@devth
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

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

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
Collaborator

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.

@mjackson mjackson closed this Nov 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment