小胡子和哈姆尔

发布于 2024-12-17 09:42:34 字数 285 浏览 2 评论 0原文

我有这个 haml/mustache 模板:

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

并且我有非法嵌套:在纯文本中嵌套是非法的错误。

我在 Sinatra 中渲染它

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

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪淡了忧伤 2024-12-24 09:42:34

我不确定是否使用 Sinatra 渲染,但使用此命令:

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

此数据文件 example.yml

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

和模板 (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 文件。希望这对您有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文