Templates
Saaze uses the Blade template engine, made popular by the Laravel framework, for it's templates. Blade is great because it's simple, powerful, and does not restrict you from using plain PHP code in your templates. In fact, all Blade templates are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your site.
For example, the Blade template for a collection might look like this:
To find out more about how to use Blade templates, see the Blade documentation on the Laravel website.
Template hierarchy
A Saaze site needs a minimum of three templates to operate:
collection.blade.php
- Displays a collection archiveentry.blade.php
- Display an individual entryerror.blade.php
- Displays an error page (e.g. 404, 500, etc.)
You can override templates for specific collections by creating index
and entry
templates in a subdirectory with the same ID as the collection. For example, for a posts
collection, the template file locations would be:
templates/posts/index.blade.php
templates/posts/entry.blade.php
Individual entries can also override which template is used to display them by specifying a template
in their Yaml frontmatter. For example, this entry would use the template custom.blade.php
if it existed:
Collection template
A collection template will have the following variables automatically injected:
$collection
- An object containing the collection data$pagination
- An object containing entries and pagination data
The $pagination
object has the following properties:
currentPage
- The index of the current pageprevPage
- The index of the previous pagenextPage
- The index of the next pageprevUrl
- The relative URL of the previous pagenextUrl
- The relative URL of the next pageperPage
- The number of entries per pagetotalEntries
- The total number of entries in the collectiontotalPages
- The total number of pagesentries
- An array of entries
Entry template
An entry template will have the following variables automatically injected:
$collection
- An object containing the collection data for the collection the entry belongs to$entry
- An object containing the entry data
The $entry
object will have properties for any fields defined in the Yaml frontmatter of the entry plus the following properties:
url
- The relative URL of the entrycontent
- The HTML content of the entryexcerpt
- An excerpt of the entry
Error template
The error template will have the following variables automatically injected:
$code
- The error code (e.g. 404, 500, etc.)$message
- The error message (e.g. Not Found)