Search code examples
rubyjekylljekyll-extensions

How can I make Jekyll use a layout without specifying it?


In order to keep some of my Jekyll sites simple, I'm always using the same layout. That is to say, I'm always writing something like. . .

---
layout: default
title: Here's my Title
---

. . . as the YAML Front Matter at the top of my pages.

What I'd rather write, however is only. . .

---
title: Here's my Title
---

. . . and have Jekyll assume that it should use a certain layout, as if I had explicitly written "layout: default" (or whatever), as above.

I don't see a way to specify this behavior in _config.yml. Maybe I could write a Jekyll plugin that would allow this. . . any ideas?


Solution

  • This can be done using Frontmatter defaults:

    defaults:
      -
        scope:
          path: "" # empty string for all files
        values:
          layout: "default"
    

    This setting is available since Jekyll Version 2.0.0.