如何在Jekyll中处理模板(布局)继承?

时间:2021-01-30 14:30:49

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

我想要一个模板“_layouts / template1.html”扩展(Django风格)模板_layouts / default.html。

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

我把它作为YAML前面的事情放在_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.

但显然它不能像我希望的那样工作(所有附加的标记都存在于template1.html中,但不是在default.html中不会渲染)。看起来使用template1布局的文件纯粹扩展了default.html。

Is there any way to have layouts inheritance in Jekyll?

有没有办法在Jekyll中进行布局继承?

4 个解决方案

#1


10  

What you mean is simply {{ content }}.

你的意思是{{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.

是的,布局可以通过管道传输。在您的情况下,如果页面使用template1布局,则它是template1的内容。然后,template1的结果是默认的内容。

#2


4  

Try the Liquid Inheritance Gem: https://github.com/danwrong/liquid-inheritance

试试Liquid Inheritance Gem:https://github.com/danwrong/liquid-inheritance

Reference: http://www.sameratiani.com/2011/10/22/get-jekyll-working-with-liquid-inheritance.html

#3


3  

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

Jekyll的Liquid模板非常容易扩展,您只需要确保扩展而不是覆盖所需的模板。

You may actually want to extend page and not default.

您可能实际上想要扩展页面而不是默认。

So, in your template Front Matter:

所以,在你的模板Front Matter中:

---
layout:page
---

#4


1  

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.

您的示例中的template1.html将扩展default.html,只要后者包含{{content}}块。见这里的例子。它不会做的是它不会覆盖default.html已经包含的任何内容。为此,你需要@juddlyon提到的Liquid Inheritance Gem。

#1


10  

What you mean is simply {{ content }}.

你的意思是{{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.

是的,布局可以通过管道传输。在您的情况下,如果页面使用template1布局,则它是template1的内容。然后,template1的结果是默认的内容。

#2


4  

Try the Liquid Inheritance Gem: https://github.com/danwrong/liquid-inheritance

试试Liquid Inheritance Gem:https://github.com/danwrong/liquid-inheritance

Reference: http://www.sameratiani.com/2011/10/22/get-jekyll-working-with-liquid-inheritance.html

#3


3  

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

Jekyll的Liquid模板非常容易扩展,您只需要确保扩展而不是覆盖所需的模板。

You may actually want to extend page and not default.

您可能实际上想要扩展页面而不是默认。

So, in your template Front Matter:

所以,在你的模板Front Matter中:

---
layout:page
---

#4


1  

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.

您的示例中的template1.html将扩展default.html,只要后者包含{{content}}块。见这里的例子。它不会做的是它不会覆盖default.html已经包含的任何内容。为此,你需要@juddlyon提到的Liquid Inheritance Gem。