Partials

Partial templates separate out re-usable and repeatable blocks of html into their own files. They sit within the /templates/partials folder.

Stacey essentially flattens the folder structure within /templates/partials, so you can place your partial files within whatever subfolders make sense to you. This also means that you cannot have two templates with the same name, even if they sit within different folders, or have different file extensions.

Partials can be referenced within a template by using include 'partials/path followed by the filename (and closing single quote) of the partial template you wish to include.
ie. include 'partials/assets/images.html' will be a reference to the /templates/partials/assets/images.html partial.

As with templates, partials do not need to be .html files. Stacey will recognize the following formats: .html, .json, .xml, .atom, .rss, .rdf and .txt

Partial Nesting

Partials references can also be nested within other partials. So, an example include 'partials/assets/media.html' partial could contain:

/templates/partials/assets/media.html

{% if image in page.images %}
  {% include 'partials/assets/images.html' %}
{% endif %}

{% if video in page.video %}
  {% include 'partials/assets/video.html' %}
{% endif %}

Where include 'partials/assets/images.html' and include 'partials/assets/video.html' are references to other partial files.

Recursive Partials

Partials can also include references to themselves, allowing you to recurse through nested objects (ie. walking down a tree of page.children).

A more elegant solution to the nested for loop example would be to split the code into two partials and take advantage of recursion within the include 'partials/navigation/children.html' partial.

/templates/partials/navigation/navigation.html

<ul id="navigation" class="col two">
  {% for child in page.root %}
    <li>
      <a href="{{ child.url }}">{{ child.title }}</a>
      {% include 'partials/navigation/children.html' with { 'page' : child } %}
    </li>
  {% endfor %}
</ul>

/templates/partials/navigation/children.html

{% if page.children %}
  <ol class="children">
    {% for child in page.children %}
      <li>
        <a href="{{ child.url }}">{{ child.page_name }}</a>
        {% include 'partials/navigation/children.html' with { 'page' : child } %}
      </li>
    {% endfor %}
  </ol>
{% endif %}

Note that the children.html partial includes a reference to itself, which means it will keep including itself (within itself) until the if statement no longer returns true.