11
votes

I want to have a template "_layouts/template1.html" extend (Django-style) a template _layouts/default.html.

I'm putting this as a YAML front matter in _layouts/template1.html

---
layout: default 
---
{{page.content}}

but apparently it doesn't work the way I'd like it to work (all the additional markup that is present in template1.html but IS NOT in default.html does not render). It looks like the file that uses template1 layout purely extends default.html.

Is there any way to have layouts inheritance in Jekyll?

4

4 Answers

10
votes

What you mean is simply {{ content }}.

Yes, layouts can be piped. In your case, if a page uses template1 layout, it is the content for template1. Then, the result of template1 is the content for default.

5
votes

Jekyll's Liquid templates extend pretty easily, you just have to be sure you're extending and not overwriting your desired template.

You may actually want to extend page and not default.

So, in your template Front Matter:

---
layout:page
---
1
votes

template1.html from your example will extend default.html as long as the latter contains a {{ content }} block. See here for example. What it won't do is it won't overwrite anything that default.html already contains. For that you'll need the Liquid Inheritance Gem, as mentioned by @juddlyon.