return to pancake.io
pancake.io :: documents
Templates

Templates are a great way to reuse common HTML code in your site. They are written in the Slim templating language.

Usage

  1. Create a new template and give it a name. Your Markdown content will be in the content variable which you should output in the template.
  2. In your Markdown file, add the template name to the header.
  3. Repeat step 2 for all files you wish to apply the template to.

Slim Syntax Primer

For complete and exhaustive documentation, please refer to the Slim Github repo. There are also simple syntax examples farther below.

line begins with... result
| outputs the text that follows, including HTML
' as |, but add one space to the end
= outputs the variable that follows
=' as =, but add one space to the end
== outputs the variable that follows without escaping
==' as ==, but add one space to the end
\ comment (not visible in generated HTML)
\! HTML comment
.aaa places the following content in a div with class aaa
#aaa same as .aaa, but setting id instead of class

Simple Example

Note the usage of == content. This is where the template will output our Markdown content. Double equals (==) are used because the Markdown content may have HTML, and this prevents the HTML from being escaped.

my_template

doctype html
html
  head
    title Pistachio Pizzeria
    link rel='stylesheet' href='/style.css' type='text/css'

  body
    == content

my_file.txt

---
template: my_template
---

...

Advanced Usage

You can configure templates with Slim variables. These are loaded from the page headers. Pancake invokes Slim in logic-less mode. See below for an example.

Example — Variables

This example shows how variables are passed to your template.

my_template_2

doctype html
html
  head
    title Pistachio Pizzeria
    link rel='stylesheet' href='/style.css' type='text/css'

  body
   h1 = my_variable
   #container
     == content

my_file.txt

---
template: my_template_2
my_variable: Hello World!
---

...