小胡子和哈姆尔 [英] Mustache and Haml

查看:75
本文介绍了小胡子和哈姆尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个haml/胡子模板:

I have got this haml/mustache template:

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

我遇到了Illegal nesting: nesting within plain text is illegal错误.

我在Sinatra中渲染

I render it in Sinatra

Mustache.render(haml(:index), hash)

推荐答案

我不确定使用Sinatra进行渲染,但是可以使用以下命令:

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

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

此数据文件example.yml

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

和模板(foo.haml.mustache):

and template (foo.haml.mustache ):

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

我得到以下结果:

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

请注意* .mustache文件中的缩进级别.希望对您有帮助.

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

这篇关于小胡子和哈姆尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆