mustache / mustache.github.com

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

Logic-less value key compare and default value suggestion #76

Closed vojtechportes closed 10 months ago

vojtechportes commented 8 years ago

I know this is not an issue, but it would be nice to have some possibility to compare or test value when writing block and to write default value more effective way.

To keep logic-less syntax, what about something like this?

Compare:

/* data */
{'value': 'ipsum'}

/* mustache */
{{ #value is lorem }}
    [[ Value is equal to lorem ]]
{{ /value }}

{{ ^value is lorem }}
    [[ Value is not lorem ]]
{{ /value }}

Occurence in the string:

/* data */
{'value': 'lorem': 'lorem ipsum'}

/* mustache */
{{ #value contains lorem }}
    [[ Value contains lorem ]]
{{ /value }}

{{ ^value contains lorem }}
    [[ Value doesn't contain lorem ]]
{{ /value }}

I think this is quite logic-less. More than that, I think that more can be improved eg for default values Because of following reasons.

Istead of writing this:

{{ value }}{{ ^value }} [[ No value ]] {{ /value }}

Wouldn't it be easier and more clear to have syntax like this?

{{ value, No value }}

I understand logic-less structure, it can be used by anyone, but sometimes this kind of "logic-less" code is really hard to read. And Im saying this as developer whose "logic-less" needs to be understand by non developers, by marketing people or designers. Such functionality I'm proposing could help a lot. I also know I can use handlebars instead, or I can modify mustache code, but I believe this shouldn't be prefered way.

Thanks in advance for considering my suggestions.

FrancoConci commented 5 years ago

+1

jobol commented 5 years ago

+1

I implemented the "key compare" as an extension in C implementation: https://gitlab.com/jobol/mustach

It allows interesting processing. The syntax there use = sign to compare equality and =! as an extension of the extension to compare to inequality.

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.