Layouts

A layout is a Twig template, so refer to the official documentation to know how to use it.

Fallback logic

The used layout file is determined by the following logic.

If page type is Homepage:

  1. index.html.twig
  2. _default/list.html.twig
  3. _default/page.html.twig

If page type is Section:

  1. section/$section.html.twig (Where $section is the section)
  2. _default/section.html.twig
  3. _default/list.html.twig

If page type is Taxonomy:

  1. taxonomy/$singular.html.twig (Where $singular is the taxonomy name)
  2. _default/taxonomy.html.twig
  3. _default/list.html.twig

If page type is Terms:

  1. taxonomy/$singular.terms.html.twig (Where $singular is the taxonomy name)
  2. _default/terms.html.twig

Otherwise:

  1. $section/page.html.twig (Where $section is the section)
  2. $section/$layout.html.twig (Where $layout is the layout)
  3. $layout.html.twig
  4. page.html.twig
  5. _default/page.html.twig

Variables

site

Contains all variables under site key in configuration, and those predefined variables:

Variable Description
site.menus All menus collections
site.pages All pages collections

site.menus

Variable Description
site.menus.ID.name Entry name, a string
site.menus.ID.url Entry URL, relative or absolute, you should use it with url() function
site.menus.ID.weight Entry weight, helper to order menu entry

page

Contains all page variables and those set in the page's front matter.

Variable Description Example
page.title Title Post 1
page.content File page body converted in HTML HTML
page.section Section blog
page.id Unique id blog/post-1
page.pathname Full path blog/post-1
page.path Path blog
page.name Name post-1
page.pages Pages collection (for node page) Collection
page.tags Tags array [Ta, Tb]
page.categories Categories array [Ca, Cb]
...

page.pagination

Variable Description
page.pagination.pages Paginated pages collection
page.pagination.prev Path to the previous page
page.pagination.next Path to the next page

Page taxonomy

Variable Description
page.singular Taxonomy name
page.plural Taxonomy name (plural form)
page.terms List of terms

phpoole

Variable Description
phpoole.url URL to the official website
phpoole.version Current version
phpoole.poweredby "PHPoole v" + current version

Example

<h1>{{ page.title }} | {{ site.title }}</h1>
<span>{{ page.date|date("j M Y") }}</span>
<p>{{ page.content }}</p>
<p>{{ page.customvar }}</p>

Functions

url()

Create an URL.

{{ url(page) }}
{{ url('tags/' ~ tag) }}
{{ url(menu.url) }}
{{ url('css/style.css') }}
{{ url('http://narno.org') }}

minify()

Minify a CSS or a Javascript file.

{{ minify('css/style.css') }}
{{ minify('js/script.js') }}

readtime()

Return read time, in minutes.

{{ readtime(page.content) }} min

Filters

excerpt

Truncate a string to 450 char and adds '…'.

{{ string|excerpt }}

sortByTitle

Sort a pages collection by title.

{{ pages|sortByTitle }}

sortByDate

Sort a pages collection by date.

{{ pages|sortByDate }}

sortByWeight

Sort a menu entries collection by weight.

{{ menu|sortByWeight }}

filterBy()

Filter a pages collection by variable name.

{{ pages|filterBy('section', 'blog') }}

minifyCSS

Minify CSS.

{% filter minifyCSS %}
<style>
  html {
    background-color: #fcfcfc;
    color: #444;
    font: 100%/3rem 'Raleway', sans-serif;
  }
</style>
{% endfilter %}

minifyJS

Minify Javascript.

{% filter minifyJS %}
<script>
  (function(d) {
    var wf = d.createElement('script'), s = d.scripts[0];
    wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js';
    s.parentNode.insertBefore(wf, s);
 })(document);
</script>
{% endfilter %}
Suggest a modification Next