Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle template (layouts) inheritance in Jekyll?

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?

like image 256
Julia K Szopa Avatar asked May 02 '12 21:05

Julia K Szopa


2 Answers

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
---
like image 128
mike Avatar answered Oct 30 '22 14:10

mike


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.

like image 38
jdh8 Avatar answered Oct 30 '22 13:10

jdh8