Skip to content

Plerd template guide

Jason McIntosh edited this page Aug 21, 2017 · 1 revision

Plerd includes a set of perfectly cromulent templates that will produce a decent, [Bootstrap]-based blog right out of the box. Once you get comfortable with Plerd, though, you'll likely want to customize things a bit.

And you can! Plerd templates are just Template Toolkit documents, and when you know the variables available to them, you can pull all sorts of clever tricks with them.

Let's examine each of Plerd's templates in order of descending interest, and the variables that you can invoke within your own creative mutations of them. In every case, you can examine the templates that Plerd ships with to see working examples.

To see the full list of methods and attributes that various objects (such as Plerd::Post objects) make available to you, use the perldoc command-line program with those objects' class files within this repository (e.g. lib/Plerd/Post.pm). (Or just read those classes' source code directly; the docs are more or less human-readable, down at the bottom of each file.)

wrapper.tt

This template gets wrapped around every post's own page, as well as the recent-posts page and the archive page.

Note that plerd doesn't apply wrapper.tt automatically; other templates are responsible for invoking it via Template Toolkit's inline [% WRAPPER %] directive. Thus, it doesn't define any variables itself -- it just inherits all the variables of the template invoking it. (It's free to itself invoke any variables at all, and if the calling template doesn't define them, then they'll simply appear undefined to the wrapper as well.)

post.tt

This template generates both the recent-posts page and all single-post pages. It's passed an array of one or more post objects, and it responsible for iterating through each. 9This array just happens to contain only one member, for single-post pages.)

Variables (which also get passed to the wrapper):

  • plerd: The base Plerd object.

  • context_post: If rendering a blog post's page, this is that post's Plerd::Post object. Otherwise, this has no value. (As such, you can use e.g. [% IF post_context %] ... [% END %] to define a part of the wrapper that will get displayed only in single-post context.)

  • posts: The aforementioned array of Plerd::Post objects.

  • title: If rendering a single post, the title of that post. Otherwise, the blog's overall title.

archive.tt

Generates your blog's archive page.

Varaibles (which also get passed to the wrapper):

  • plerd: The base Plerd object.

  • posts: An array containing all of this blog. Each is a Plerd::Post object.

atom.tt

jsonfeed.tt

These templates generate your blog's Atom and JSON feeds, respective. You probably don't want to tinker with them.