Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mustache and Haml

I have got this haml/mustache template:

{{#data}}
  ok
  {{#items}}
    {{#item}}
      %b ID: {{id}}
    {{/item}}
  {{/items}}
{{/data}}

And I have got Illegal nesting: nesting within plain text is illegal Error.

I render it in Sinatra

Mustache.render(haml(:index), hash)
like image 353
fl00r Avatar asked Nov 04 '22 10:11

fl00r


1 Answers

I'm not sure about rendering with Sinatra, but with this command:

cat example.yml foo.haml.mustache | mustache | haml -e

this data file example.yml

---
data:
  - items:
    - item:
      - id: 1
      - id: 2
      - id: 3
---    

and template (foo.haml.mustache ):

{{#data}}
#ok
{{#items}}
{{#item}}
  %b ID: {{id}}
{{/item}}
{{/items}}
{{/data}}

I get following result:

<div id='ok'>
  <b>ID: 1</b>
  <b>ID: 2</b>
  <b>ID: 3</b>
</div>

Pls pay attention to indentation level in *.mustache file. Hope this help you.

like image 85
WarHog Avatar answered Nov 09 '22 12:11

WarHog