kainjow/Mustache

Lists are not rendered, length doesn't work

KingDuckZ opened this issue · 2 comments

I wrote this short test:

#include "Mustache/mustache.hpp"
#include <iostream>

int main() {
        using kainjow::mustache::mustache;
        using kainjow::mustache::data;

        const char* const model = "Test {{array.length}} - \"{{array}}\"\nwas:{{#array}}\n\t- {{.}}\n{{/array}}\n";
        mustache tmpl{model};
        data context{data::type::list};

        std::cout << "--------- model ------------\n" << model << '\n';
        context << data{"one"} << data{"two"} << data{"three"};

        std::cout << "--------- render -----------\n";
        std::cout << tmpl.render({"array", context});
        return 0;
}

And this is the output I get:

--------- model ------------
Test {{array.length}} - "{{array}}"
was:{{#array}}
        - {{.}}
{{/array}}

--------- render -----------
Test  - ""
was:
        - one

        - two

        - three

I tried running the same thing on the mustache demo page, so input

Test {{array.length}} - "{{array}}"
was:{{#array}}
	- {{.}}
{{/array}}

and

{
  "array": ["one", "two", "three"]
}

and I get the expected result:

Test 3 - "one,two,three"
was:
- one
- two
- three

It's not quite as expected since the demo page is eating up my tab character, but it's still closer to being correct.

Length is a JavaScript property, it's not part of Mustache, as far as I know. You'd need to add that as its own separate variable.

And using an array as a variable isn't supported either (again, probably a JS thing if that works there).