如何访问中间人4中的文章布局数据属性?

How to access the article layout data property in middleman 4?

我正在尝试从 Middleman 4 迁移我的博客。在我的 index.html.erb 文件中,我有这样的代码:

<% page_articles.each_with_index do |article, i| %>
    <% if article.data.layout == 'post' %>
        <%= partial "post", :locals => { :article => article} %>
    <% elsif article.data.layout == 'micro' %>
        <%= partial "micro", :locals => { :article => article} %>
    <% end %>
<% end %>

这在 Middleman 3 中运行良好,我可以根据每个 post 前言中定义的布局 属性 使用不同的部分。

但是,在 Middleman 4 中,layout 属性 在 article.data 中不再可见。

所有其他变量都在那里。到目前为止,完成这项工作的唯一方法是像这样声明 frontmatter:

---
layout: post
l: post
title:  "Foo"
date:   2012-10-22 15:14:01
categories: Bar
tags:
---

并使用 article.data.l 而不是 article.data.layout。然而,这需要我重写所有文章并且似乎是多余的。

根据布局在索引页上呈现文章的正确方法是什么 属性?

在中间人 4 中,layout 属性 被认为是 option 而不是 data

您应该能够使用 article.options.layoutarticle.options[:layout].

访问页面 layout 属性 的值