A page can have only one layout , but layouts can be nested.
I have three _layouts :
- master.html
- default.html
- post.html
The master layout has the entire basic structure that is needed for any page. It looks something like this:
<html> <head> <title>{{ page.title }}</title> </head> <body> {{ content }} </body> </html>
I use the default layout for most pages that are not blog posts. I make extensive use of several page variables in the front of YAML pages. The layout looks something like this:
--- layout: master --- <h1> {{ page.title }} {% if page.subtitle %}<small>{{ page.subtitle }}</small>{% endif %} </h1> {% if page.description %}<p>{{ page.description }}</p>{% endif %} {{ content }}
I am using post layout for _posts pages. It looks like this:
--- layout: default --- <p>Posted {{ page.date }}</p> <ul>{% for tag in page.tags %}...{% endfor %}</ul> {{ content }}
Every blog post I make, I use a post layout, and they inherit all three layouts.
If you want to have reusable markup fragments, then I would recommend using _includes .
kzh
source share