How to get YAML files to render in middleman with erb

泄露秘密 提交于 2019-12-04 18:25:17

I'll limit this answer strictly to accessing data from the YAML file. This will get you the data output you are after, and you can decide how to style it from there.

Assuming your file is named mydata.yaml and located in the /data folder of your Middleman app, the following code will work to generate the nested data loops you are looking for:

<h1><%= data.mydata.main_title %></h1>

<% data.mydata.sections.each do |section| %>
    <h2><%= section.section_title %><h2>
    <% section.items.each do |item| %>
        <h3><%= item.title %></h3>
        <h4><%= item.value %></h4>
    <% end %>
<% end %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!