Helpers

Helpers are small functions exposed to your templates. The built-in ones are intentionally few; you add the rest yourself with asimov.register() (see Plugins).

Built-in helpers

{{style "main"}} inserts <link rel="stylesheet" href="...">
{{script "app"}} inserts <script src="...">
{{link "url" "label"}} renders <a href="url">label</a>
{{import "partial"}} inlines another .tmpl
{{include "path.txt"}} inlines raw content from a content file

Asset helpers (style, script) read a manifest built by asimov-static so the URL always points to the final, cache-busted file.

Writing your own

A helper is just a function registered on the public interface. Once registered, it becomes available both in JavaScript and inside {{ }} blocks.

lib/helpers/year.js
module.exports = function year () {
return new Date().getFullYear();
};
// index.js
var year = require('./lib/helpers/year');
module.exports = function plugin () {
asimov.register('year', year);
};

In a template:

<footer>&copy; {{year}} asimov.js</footer>

Helpers vs. variables

Helpers run at render time and can accept arguments; frontmatter keys are static strings looked up from the page context. If something is computed, use a helper. If it lives in the file, use a key.