You are not logged in.
I have tried to render a simple array with SynMustache
json := '["a","b","c"]';
mustache := TSynMustache.Parse('<ul>{{#.}}<li>{{.}}</li>{{/.}}</ul>');
html := mustache.RenderJSON(json);
But I can't, because SynMustache don't render this template. I think this is a bug. Please see this entry in Stackoverflow.
Offline
I added a ticket
Offline
There is an easy workaround to this limitation, for sure, which is to define a property containing the array.
Even if it is rendered by the JavaScript renderer, it is not documented as such.
There is even no mention of {{.}} in https://mustache.github.io/mustache.5.html
And the official specification files does not test a top level array, but only the cases supported by SynMustache:
# Implicit Iterators
- name: Implicit Iterator - String
desc: Implicit iterators should directly interpolate strings.
data:
list: [ 'a', 'b', 'c', 'd', 'e' ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(a)(b)(c)(d)(e)"'
- name: Implicit Iterator - Integer
desc: Implicit iterators should cast integers to strings and interpolate.
data:
list: [ 1, 2, 3, 4, 5 ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(1)(2)(3)(4)(5)"'
- name: Implicit Iterator - Decimal
desc: Implicit iterators should cast decimals to strings and interpolate.
data:
list: [ 1.10, 2.20, 3.30, 4.40, 5.50 ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"'
- name: Implicit Iterator - Array
desc: Implicit iterators should allow iterating over nested arrays.
data:
list: [ [1, 2, 3], ['a', 'b', 'c'] ]
template: '"{{#list}}({{#.}}{{.}}{{/.}}){{/list}}"'
expected: '"(123)(abc)"'
See https://github.com/mustache/spec/blob/m … ctions.yml
So IMHO it is not a bug, but a limitation to an undocumented feature.
Online
@ab, I agree with you. I haven't read the official specification, only StackOverflow. This is a undocumented feature.
Offline
While implementing a TFB benchmark I found they use a top-level array in template (not a problem - I modify a template - it's allowed).
I also sometimes use a top level array in my templates rendered by JS.
So this is common feature and may be can be implementer in future.
Offline
Starting from https://github.com/synopse/mORMot2/commit/fed0021366c top level arrays is supported
Offline