访问多层 YAML 和 Middleman [英] Accessing multi-layered YAML and Middleman

查看:27
本文介绍了访问多层 YAML 和 Middleman的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看了这两个链接,YAML 和 Middleman 一起使用就明白了很多:中间人文档(本地数据)解析和编写 YAML

我现在遇到的问题是访问多个级别的内容.

YAML(存在于数据/项目中)

- quote: 这是一个引用归属:凯特某事附加功能:- 额外的一个- 额外两个- 额外三个- 引用:废话废话归属:唐娜·多伊附加功能:- 另一个额外的- 另一个额外的

.HTML.ERB

<% data.projects.each do |f|%><div><%= f["quote"] %><%= f["属性"] %><%= f["extras"] %></div><%结束%>

上面使用 Middleman 运行很顺利,但是,我如何访问 "extras:" 下的数据并将它们吐出到列表中?

换句话说,这是在构建中编译的:

<div>这是引用 Kate 一些额外的一个额外的两个额外的三个</div>

这是需要达到的结果:

<div>这是引用 Kate 的东西<ul><li>额外的</li><li>额外的两个</li><li>额外三个</li>

预先感谢您查看此问题.如果您需要对上述任何内容进行澄清,请告诉我,我会尽力进一步解释.

解决方案

f["extras"] 只是另一个数组,所以你可以像迭代 一样迭代它数据项目:

<% data.projects.each do |f|%><div><%= f["quote"] %><%= f["属性"] %><ul><% f["extras"].each do |extra|%><%#这里是内循环%><li><%=额外的%</li><%结束%>

<%结束%>

After taking a look at these two links, using YAML with Middleman has become a lot more clear: Middleman Docs(Local Data), parsing and composing YAML

The issue that I'm running into now is accessing multiple levels of content.

YAML (lives in data/projects)

- quote: This is a quote
  attribution: Kate Something
  extras:
      - extra one
      - extra two
      - extra three

- quote: Blah blah
  attribution: Donna Doe
  extras:
      - another extra
      - another extra

.HTML.ERB

<% data.projects.each do |f| %>
    <div><%= f["quote"] %>  <%= f["attribution"] %> <%= f["extras"] %></div> 
<% end %>

The above is running smoothly with Middleman, however, how can I access the data underneath "extras:" and spit them out in a list?

In other words, this is what is compiled in build:

<div>This is a quote  Kate Something extra oneextra twoextra three</div>

This is the result that needs to be achieved:

<div>This is a quote  Kate Something 
  <ul>
    <li>extra one</li>
    <li>extra two</li>
    <li>extra three</li>
  </ul>
</div>

Thank you in advance for taking a look at this issues. Please let me know if you need clarification on any of the above, and I'll try to explain further.

解决方案

f["extras"] is just another array, so you can iterate over it the same way you iterate over data.projects:

<% data.projects.each do |f| %>
    <div><%= f["quote"] %>  <%= f["attribution"] %>
      <ul>
        <% f["extras"].each do |extra| %> <%# inner loop here %>
          <li><%= extra %></li>
        <% end %>
      </ul>
    </div> 
<% end %>

这篇关于访问多层 YAML 和 Middleman的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆