Documentation

  1. Overview
  2. Creating Pages
    1. Editing Content
  3. Editing Templates
    1. Templating Language
    2. Assets
  4. Variable Types
    1. @variables
    2. $collections
    3. :partials
  5. RSS/Atom/JSON
  6. Download
    Stacey v2.3.0
  7. News & Updates
  8. Support
Stacey

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 a : followed by the filename of the partial template.
ie. :images 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 recognise the following formats: .html, .json, .xml, .atom, .rss, .rdf & .txt

Partial Nesting

Partials references can also be nested within other partials. So, an example :media partial could contain:

/templates/partials/assets/media.html

if $images do
  :images
endif

if $video do
  :video
endif

Where :images & :video 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 $children).

A more elegant solution to the nested foreach loop example would be to split the code into two partials and take advantage of recursion within the :children partial.

/templates/partials/navigation/navigation.html

<ol id="navigation">
  foreach $root do
    <li><a href="@url">@page_name</a> :children </li>
  endforeach
</ol>

/templates/partials/navigation/children.html

if $children do
  <ol>
    foreach $children do
      <li><a href="@url">@page_name</a> :children </li>
    endforeach
  </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.