Skip to content

Instantly share code, notes, and snippets.

@neilkinnish
Created May 19, 2014 07:24
Show Gist options
  • Save neilkinnish/180f8da8b272f6c4b361 to your computer and use it in GitHub Desktop.
Save neilkinnish/180f8da8b272f6c4b361 to your computer and use it in GitHub Desktop.
/*
Standard way you can change title based upon collection page, keep in mind that the collections yaml meta becomes available
to it's layout file under the model namespace.
model.title will be pulled from the collections page yaml meta
*/
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<title>{{ model.title }}</title>
</head>
<body>
</body>
</html>
/*
Blocks are interesting as you can create as many as you want, add default content, inject from the child. If no default and nothing injected they simply don't render.
If you have this in your title:
*/
<title>{% block title %}default title{% endblock %}</title>
/*
It allows you to inject a title from any child page and if you did this...
*/
<title>{% block title %}{% endblock %}{{ model.title }}</title>
/*
You can either inject from any page or layout that inherits this layout - through the block or inject via a model or collection meta.
Another cool thing you can do is create a global variables block, like so..
*/
{% block vars %}{% endblock %}
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<title>{{ pageTitle }}</title>
</head>
<body>
</body>
</html>
/*
Notice the "vars" block at the top of the layout file and then the "pageTitle" variable in the title. This block essentially allows you to set variables from child pages which can then be used in the layout or in fact anywhere below this block including includes and pages or layouts that inherit this layout, etc.
I could pass my variables from the inheriting page or layout like so...
*/
{% block vars %}
{% assign pageTitle = "Example" %}
{% capture anotherVariable %}another example{% endcapture %}
{% endblock %}
/*
Hope this helps!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment