The Context

Every template file is passed a context. There are two types of context that a template file may be passed: a list context and a page context. Each type of context has its own unique variables assigned to it by Aoife and there are a number of base variables common to both types of context. Additionally, variables defined in a post’s frontmatter are also injected into the context.

Single posts have just one context. However, the context within a list page changes when within an interation of a {{foreach} }{{endeach} } block. This is because a list page represent a collection of posts, each one having its own context.

For example, in a single post the tag {{title} } returns the title of the post. However in a list post, within a {{foreach} }{{endeach} } block the {{title} } tag returns the title of the post in the current iteration. Consider the following three Markdown files:

File structure
content/review/Die Hard.md    // http://example.com/review/die-hard.html
content/review/Avatar.md      // http://example.com/review/avatar.html
content/review/Star Trek.md   // http://example.com/review/star-trek.html
Die Hard.md
;;;
"title": "Die Hard (1988)"
;;;
## Yippee ki-yay! ##
Avatar.md
;;;
"title": "Avatar (2009)"
;;;
## Open Pandora's box ##
Star Trek.md
;;;
"title": "Star Trek (2009)"
;;;
## To boldly go where no one has gone before ##

When Aoife renders the page http://example.com/review/avatar.html it will call the single.html template file for the theme. Let’s say the contents of that file is:

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

The output will be:

<h2>Avatar (2009)</h2>

If, however, Aoife is rendering a list of the all the reviews at http://example.com/review/index.html it will call the list.html template file. Let’s say the contents of that file is:

{{foreach} }
  <h2>{{title} }</h2>
  <hr />
{{endeach} }

The output will be:

<h2>Die Hard (1988)</h2>
<hr />
<h2>Avatar (2009)</h2>
<hr />
<h2>Star Trek (2009)</h2>
<hr />

Modified: Dec 21, 2016 at 18:39:13

Aoife v0.9.0 documentation