Render a partial template.

Example 1: The header

The most common usage of a partial is to add a header or navigation into a layout file, like this:

  {{ partial:header }}

  <div class="main">
    {{ template_content }}

The {{ partial:header }} tag would output the contents of site/themes/theme_name/partials/header.html.

Splitting your templates up into partials is a nice way to keep things clean and organized. Another great way to keep things tidy is to split up your partials into subdirectories:

|-- nav/
|   |-- top.html
|-- authors/
|   |-- meta.html
|-- session/
|   |-- message.html

To render a partial that’s inside a subdirectory, we would simply add {{ partial:$folder/$filename }} in our template. In other words, to get our top nav partial we would do {{ partial:nav/top }}.

Example 2: The reusable chunk

Another common usage for a partial is to pass in data into a reusable chunk of template code.

Here’s a partial which outputs a list.

<h3>{{ header }}</h3>
  {{ items }}
    <li>{{ value }}</li>
  {{ /items }}

In a page, we might have a list of animals.

  - Stag
  - Rhino
  - Alligator

Then in our template, we want to output those animals using the partial.

  {{ partial:list header="Favorite Animals" :items="animals" }}

The resulting output would look like this:

<h3>Favorite Animals</h3>

The :items parameter was prefixed by a colon, which means it will be retrieved from the context.



tag part

The name of the partial file, relative to the partials folder. This is part of the tag, not actually a parameter. For example, you'd use partial:list to load the list partial.



The name of the partial. This is just a more verbose syntax, but can allow you to use a variable for the partial name. eg. {{ partial src="{my_partial}" }}


multiple params

Any additional parameters specified will be sent into the partial as variables.

Last modified on June 13, 2017