Tutorial 12 of 12 9 min

Building Templates from Your Project

A freeform template is a page you write yourself in HTML, CSS and JavaScript. Its code can read your project through alistair: your characters, scenes, comments, dialogue and word counts. A cast board, a scene tracker or a word-goal dashboard takes a few lines, and it stays up to date as you write.

Prefer not to write code? The visual builder makes forms by clicking fields onto a page (Tutorial 10) and can list, look up, count and calculate from your project too (Tutorial 11). Its code button turns a visual template into one you can carry on with here.
1

Start a new template

Open Template Manager and click New Template. Under Built on your project's data are seven working examples: Cast Board, Scene Tracker, Mentions Finder, Word Goal, Dialogue Balance, Editorial To-Do and Name Generator. Each one is ready to use, and each is a good place to start your own.

New Template dialog: visual examples at the top, then seven code examples built on the project's data, then Visual Builder and Freeform from scratch
2

Open an example

Choose Scene Tracker. The code is on the left, in HTML, CSS and JS tabs with colors like VS Code. The Live Preview on the right already shows your own scenes, in columns by status with their word counts. Change the code and the preview updates after a moment, or press Ctrl+Enter to refresh it straight away.

Freeform builder with the Scene Tracker example: JavaScript on the left calling alistair.scenes(), and the preview showing five chapters in Draft, Revision and Final columns
The key line is const scenes = await alistair.scenes();. Every call returns a promise, so put await in front. You can do that anywhere in the JS tab.
3

See everything you can read

Click the API tab. It lists every call: project and stats; documents and search; characters, locations, factions, lore, scenes, beats and relationships; comments, dialogue, versions and daily progress. Each entry says what it returns. Try it runs the call on your project and shows the result, and Insert adds a working example to your code.

The API tab with alistair.characters() tried on the project, showing Elin Hale's sheet as data, and the entries for locations, factions, species and more below
What your template reads is a copy. It can read your project but never change it, which makes templates safe to share. The full list is in the Template API reference.
4

Write your own

In the JS tab, type alistair. and a list of the calls appears, each with a line saying what it does. Keep typing to narrow it, then press Enter to choose one. The editor also closes brackets and tags for you, and Ctrl+/ comments out a line.

JS tab with alistair.ch typed and a suggestion for characters() with its description
5

Find mistakes with the Console

Anything your code logs with console.log() appears in the Console under the preview. If something goes wrong, the error appears there with a link to its line, and is also written right under that line in the editor. Here, c.nmae should be c.name.

The Console showing '4 characters' and an error, Cannot read properties of undefined, linked to JS line 30, with the same error shown in red under line 30 in the editor
Shift+Alt+F tidies your code, Ctrl+F finds and Ctrl+H replaces. The split button shows two tabs side by side, for example your HTML beside your JS.
6

Check it in light, dark and narrow

The buttons above the preview show your template as narrow as the side panel, as wide as a page, or full width, and in the light or dark theme. Use the theme's colors in your CSS (var(--text-primary), var(--bg-editor), var(--accent-color)) and your template follows whichever theme the writer uses.

The Scene Tracker previewed at side-panel width in the dark theme, its columns stacked into one
7

Save it to a folder

Give your template a name, choose its folder from the list (or + Custom folder… to make a new one), and click Save or press Ctrl+S. It then appears in that folder's Add new… beside the built-in document types. Here a Cast Board saved to Characters sits next to Character Sheet.

Create New Document in the Characters folder, offering Character Sheet and the Cast Board template
Every save keeps the version it replaced. Click History in the builder, or the history button on the template's card, to look at an earlier version and restore it.
8

Use it as you write

A document made from your template reads your project every time it opens. The Cast Board shows every character as a card in their color; click one to open their sheet. Templates that call alistair.on('change', …), like all seven examples, also refresh when you save anything in the project, even in another tab.

A Cast Board document showing Elin Hale, Tobias Wren, Ressa Morne and Old Calder as colored cards with role, age and occupation, and filter buttons by role
9

Change your project, with permission

Most calls only read. A few change your project: alistair.createDocument({ title, … }) makes a document, alistair.setField(id, field, value) changes a field of another template's document, and alistair.setStatus(id, status) marks a scene or document as draft, revision, review, final or published. Templates can be shared, so Alistair asks first. The writer chooses Allow, Always allow this template or Don't allow, and every change shows a message with Undo. In the builder's preview nothing changes; you're told what would have happened.

Allow this change? A template wants to change your project: Create a Magic Item called The Storm Glass in World Building, with Don't allow, Always allow this template and Allow
const spell = await alistair.createDocument({ title: 'Fireball', fields: { kind: 'Instant' } });
await alistair.setStatus(sceneId, 'revision');
For a goal, a setting or a list your template keeps for itself, use alistair.setData(key, value) and alistair.getData(key). They're kept in the project with your writing, and they don't ask, because only that template uses them.
← Back to all tutorials