0

I am trying to migrate my blog from Middleman 4. In my index.html.erb file I have code like this:

<% 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 %>

This worked fine in Middleman 3 and I could use a different partial depending on the layout property defined in each post's front matter.

However, in Middleman 4 the layout property is no longer visible in article.data.

All other variables are there. So far the only way to make this work is to declare frontmatter like this:

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

And use article.data.l rather than article.data.layout. This, however, requires that I rewrite all of the articles and seems redundant.

What is the correct way to render articles on the index page with different partials depending on the layout property?

Jozef Legény
  • 1,157
  • 1
  • 11
  • 26

1 Answers1

1

In Middleman 4 the layout property is considered an option rather than data.

You should be able to access the value of a page's layout property using article.options.layout or maybe article.options[:layout].

Adam Hollett
  • 421
  • 2
  • 8