Custom Post Templates

You probably already know that Postleaf themes have a template called post.dust. This is the default template that Postleaf will use to render all your blog posts. It usually has things like title, content, author info, and links to related posts — normal things you'd expect from a blog.

What you probably don't know is there's a really useful feature built into Postleaf called Custom Post Templates, and they open up a whole new world of creativity for designers.

Types of Templates

Your theme can have as many custom post templates as you want, and any post can use any of those templates. Think about that. You can create a template for literally anything. Here are a few ideas:

  • A featured image post
  • A microblog post
  • A two-column post
  • A landing page
  • A contact page

The possibilities are endless, and I'm sure users will surprise me with how they take advantage of it.

Creating Templates

It's probably easiest to start by duplicating post.dust and modifying it, but you're welcome to create the template from scratch if you prefer. Give the file a name that makes sense.

Like the standard post template, all custom post templates must contain one {@title editable="true"/} helper and one {@content editable="true"/} helper.

For more info about Dust.js templates, refer to the themes overview.

Defining Templates

Before you can use custom post templates, you need to define them in theme.json. Just open it up and add a line like the following to the root object:

"customPostTemplates": [
{ "name": "Micro", "filename": "micro.dust" },
{ "name": "Page", "filename": "page.dust" }
]

Each template should have a name and a filename property. Filenames must be relative to the theme folder.

Once you've saved the file, you're ready to use your new templates!

Using Templates

To assign a template to a post, open the post for editing. From the settings panel, select the desired template from the Template menu.

Now just close the settings panel and your post will use the template you selected.


Custom post templates are an incredibly powerful feature that makes Postleaf incredibly flexible not only as a blogging platform, but as a CMS in general.