hablo/doc/Template-variables.md

5.9 KiB

Template variables

Here is the full list of the available text template variables that you can customize in your wording file and the name of the variable parameters some of them expect.

Variables are prefixed by a $ and may be enclosed in brackets { } to lift any ambiguity and separate the variable from the surrounding characters (exemple : does the template the $nth refers to a nth variable or is it the variable n followed by the literal characters th ? the first interpretation prevails, and if you want the second one you should write the ${n}th).

All template variables are checked at «compile-time» when the blog is generated and so syntax errors, missing or unexpected variables etc. are caught early.

Conditional blocks

Now some contexts may vary a bit and sometimes «lack» a variable so some templates like metadata need a way to «catch» those possible null values and keep templating. You could for instance decide that most articles of your blog aren't signed because they obviously come from you or the organization that publishes the blog but that when the blog features an article by a special guest it needs a special mention and you would put the corresponding part using the ${author} variable in a conditional block. The syntax to do so and «warn» the templating system of possible null values is to enclose the corresponding optional part inside {? ?} like so :

allPage = The articles{? about ${tag}?}

This will yield just The articles on the general pages without tags and The articles about sea turtles on the pages for the tag sea turtles. Note that conditional blocks are «flat», you can't nest one under another.

Available variables

The text used in the link to the full page on the latest page of the same category.

allPage

The <h2> title used on the full page for articles.

It can use the variable named $tag : the name of the tag for the given page. Be careful that this variable will be null for the untagged «general» pages, so you want to escape it using the conditional syntax described above if your template string does contain ${tag}.

The text displayed after the comments as a link to the toot that opens the comments section inviting visitors to comment the post.

commentsSection

The content of the <h2> element at the begining of the comments on the pages of articles that have comments enabled.

dateFormat

This isn't really a template per-se but impacts the way the dates are generated to use in the metadata template. More precisely it contains the arguments passed to the toLocaleDateString method. It can thus only consist in a locale name, but since toLocaleDateString also accepts an object as second argument, you can write the whole thing using JSON like this :

dateFormat = ["en-AU", {"month":"long", "day":"2-digit"}]

The text used in the link to the latest page on the full page of the same category.

latestPage

The <h2> title used on the latest page for articles. The latest page without tags is the «main» page of your blog so this is more or less the first title that people see when they come to your blog.

Just like the allPage above it makes use of the $tag variable, that will be null for the untagged «general» pages. Again, see the conditional section above to handle this properly.

metadata

The template of the text used to present the metadata associated to each article. This template is used both in the preview of an article on any page that lists it and on the article's page itself. It expects three possible variables

  • $author
  • $date
  • $tags

As mentioned in the introduction, some of them may be null so you may want to protect the whole metadata template with {? ?} like it is done in this variable's default value :

metadata = {?by ${author} ?}on ${date}{? tagged ${tags}?}

If an article has an author, the rendered metadata string will start with «by », otherwise it will directly start with «on ». Likewise all articles with tags will have their metadata end with « tagged » and then the list of comma-separated tags but if an article doesn't have tags, it will simply end after the date.

This template variable contains the text displayed in the link element pointing to the RSS feed to each list page. This template is a constant and doesn't expect any templating variable.

rssTitle

This template variable contains the title attribute of the link element pointing to the RSS feed to each list page that will be visible on mouse hover. The only templating variable it expects is $tag (which should be preferably protected if you use it because $tag will be null on the main page containing a link to the general feed containing all the articles published on your blog).

tagsList

The content of the <h2> element in the navigation <div> that lists all the tags of your blog.