How to handle template (layout) inheritance in Jekyll?

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

I put this as the front YAML element in _layouts / template1.html

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

but apparently it doesn’t work the way I would like it to work (all the additional markup that is present in the template1.html file but is NOT in default.html is not displayed). It looks like a file that uses layout1 layout just extends default.html.

Is there a way to have layout inheritance in Jekyll?

+7
source share
4 answers

What do you mean by simply {{ content }} .

Yes, layouts can be transmitted through channels. In your case, if the page uses the layout template1, this is the content for template1. Then the result of template 1 is the default content.

+10
source

Jekyll Liquid templates are fairly easy to distribute, you just need to be sure that you are expanding and not overwriting the template you need.

You might want to expand the page, not the default.

So, in your Front Matter template:

 --- layout:page --- 
+3
source

template1.html from your example will expand default.html if the latter contains the {{ content }} block. See here . What he does not do is not overwrite everything that default.html already contains. To do this, you will need the Liquid Inheritance Gem, as mentioned by @juddlyon.

+1
source

All Articles