mustache / mustache.github.com

The {{official}} website
http://mustache.github.io/
Other
2.31k stars 293 forks source link

Lists delimiter character #104

Closed iax7 closed 10 months ago

iax7 commented 6 years ago

When working with lists, sometimes you need to have a delimiter character like a comma, to separate them, but when the last item is rendered that comma should not be added.

I'm thinking in something like this as a starting point:

export no_proxy="{{#noproxy}}{{.}}{{=,}}{{/noproxy}}"

the {{=,}} is the delimiting character that should be used when is not the last item.

jobol commented 6 years ago

That an is interesting proposal to my eyes. I'll add it in my implementation but not with the char =. I think that the char , is a better choice. It will be {{,,}} or {{,;}} or {{, }}.

bobthecow commented 6 years ago

There's currently nowhere in the mustache spec where something typed inside curly brackets is printed. Using a comma that's inside a tag like this is akin to using a function or variable name to decide what to print, rather than passing data like a string :)

To be consistent, it should probably have the value between matched tags, the way sections, blocks, etc work.

jobol commented 6 years ago

Agreed.

I had a ideas about putting the data to print between {{,}} and the closing enumeration {{/...}} but it seems more complicated to implement because it currently doesn't enforce restriction on the enclosed content.

I also mind about specifying the separator in {{/....}} like in {{,,/...}} or {{/...,,}} but it raise escaping issues.

ppKrauss commented 3 years ago

No solution here?

It is a classic problem, that makes people to abandon Mustache.

jobol commented 3 years ago

See it is related to issue #140

jgonggrijp commented 10 months ago

Closing this because this repository is about the website and not about the Mustache template language. Please take comments about the template language to https://github.com/mustache/spec/discussions.

Previous discussions about this particular topic can be found via https://github.com/mustache/spec/discussions/163, https://github.com/mustache/spec/discussions/153 and https://github.com/mustache/spec/discussions/164.