Disco

Disco is Aoife’s templating language. In essence, it’s normal HTML with a limited number of tags that will be transformed by Aoife during rendering into the required value.

Basic syntax

As mentioned above, Disco template files are normal HTML files with the .html file extension but with the addition of variables and functions known as tags. Tags are called within double curly braces: .

Variables

Each template file has a context object made available to it. Aoife passes either a page context or a list context to a template file, depending on the type of page being rendered. More detail is available in the Variables section.

A variable is accessed by referencing the variable’s name within a tag, e.g. the title variable:

<title>{{title} }</title>

Partials

To include the contents of another template file in a template file, we use the {{partial template-name} } tag where template-name is the name of a template file in the partials/ folder (minus the .html extension).

For example, given a file called header.html in partials/ like this:

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <link href="{{assets} }/css/bootstrap.min.css" rel="stylesheet">
</head>

We can include it in our single.html template file like this:

{{partial header} }

<body>
  <p>Hello!</p>
</body>

Iteration

Disco is deliberately logic-less. The only non-variable tag is the {{foreach} } {{endeach} } block. Tags and HTML enclosed within this block are run for each post in the current Context. For example, if we assume that the current context has three pages then the following code:

{{foreach} }
  <h2>{{title} }</h2>
  <p>Posted at {{date.hour} }:{{date.minute} }</p>
  <hr />
{{endeach} }

Would output the following HTML:

<h2>My first post<h2/>
<p>Posted at 13:15<p/>
<hr />
<h2>My second post<h2/>
<p>Posted at 08:05<p/>
<hr />
<h2>My third post<h2/>
<p>Posted at 20:45<p/>
<hr />

The {{foreach} } {{endeach} } block only has meaning in List templates.

Modified: Apr 30, 2017 at 22:47:22

Aoife v0.9.0 documentation