Skip to content

Nested Layouts using YAML Frontmatter #251

Closed
jmulder opened this Issue Jan 26, 2012 · 10 comments

7 participants

@jmulder
jmulder commented Jan 26, 2012

I'd like to be able to nest layouts by defining them in Frontmatter. I know middleman 3.0 will be introducing a wrap_layout method, but I'd like to be consistent in the way I define layouts throughout the entire project.

@tdreyno
Middleman member
tdreyno commented Jan 27, 2012

Can you post a step by step description of your proposal? Give an example YAML frontmatter?

@jmulder
jmulder commented Jan 28, 2012

It's exactly the same functionality as wrap_layout provides, except called from the Frontmatter.

index.html.erb

---
layout: homepage
---
<h1>Homepage</h1>
layouts/homepage.erb

---
layout: master
---
<div id="homepage">
    <% yield %>
</div>
layouts/master.erb

<!doctype html>
<html>
<head></head>
<body>
    <% yield %>
</body>
</html>

The simplest use-case would allow me to have a generic master layout that would likely include HTML for the HEAD along with some high level structural HTML, followed by a specific layout. A more interesting would be one that allowed me to include a partial that itself would include a layout.

I'd like to minimize the amount of logic surrounding the HTML, so allowing me to define this through the YAML Frontmatter would give me the benefit of consistency and the future possibility to parse this data.

@tdreyno
Middleman member
tdreyno commented Jan 28, 2012

The difference between:

<% wrap_layout :master do %>
  Hi
<% end %>

And

---
wrap_layout: master
---
Hi

Is pretty minimal. But shouldn't be difficult to implement. Actually seems to make a little more sense in the Frontmatter as it's metadata.

@tdreyno
Middleman member
tdreyno commented May 9, 2012

Punting on this until 3.1

@iwarner
iwarner commented Apr 23, 2013

This is basically how Jekyll handles nested layouts +1 for this.

@geoffreywiseman

Yeah, this is what I was expecting when I first started using Middleman, in part because I'd used Jekyll. The existing process is fine, but using front-matter seems slightly better for most purposes. wrap_layout has some flexibility that front-matter doesn't have in terms of deciding exactly where to insert the layout wrapping, but for most purposes, I'd want it to be outermost anyway.

@bhollis
Middleman member
bhollis commented Apr 23, 2013

A pull request for this would be appreciated!

@ungoldman

Would be really nice to be able to add some frontmatter to layouts in general, like for example css or arbitrary data like section, so then a template can inherit things from layout outside of straight html/erb type stuff.

@Aupajo
Aupajo commented Mar 26, 2014

Is it possible to use YAML in layouts, then? How do you access the data?

@bhollis
Middleman member
bhollis commented Mar 26, 2014

No, it is not.

@tdreyno tdreyno closed this Jul 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.