Writing templates
Templates define a book's layouts, print formats, settings and editors in TypeScript and React. Each book has its own template/ folder. Edit it while the book is open to see changes and errors in ImageFlow.
Start here
- Create a book from Photobook and open
template/index.tsxin your editor. Included declarations andtsconfig.jsonprovide type checking without installing packages. - Read Package and Declaration.
- Adapt an example template.
minimal.tsxis the smallest complete example. Examples use generic fonts; bundle fonts before print export. - Use the Book check to catch layout and content issues.
- Import the finished template folder into the library to create new books or share it.
For help from an agent, see Connecting agents and the authoring workflow.
Template API reference
These topics are also available through ImageFlow's MCP tools and the template skill.
| Topic | What it covers |
|---|---|
| Authoring workflow | MCP tools, revisions and drafts. |
| Project commands and preview targets | Batch edits, parameter scopes and previews. |
| Package | Imports, examples and contract-1 features. |
| Declaration | defineTemplate and layout builders. |
| Page layouts | Page roots, geometry and facing pages. |
| Parameters | p.* types, options and defaults. |
| List parameters | List items, IDs and edit commands. |
| Boxes and elements | Photo boxes, Markdown flow, text.meta and composing a text. |
| Print format | Trim, bleed, safe areas and pagination. |
| Template library | Import, previews and openingSpreads. |
| Switching layouts | Content, crops and saved layout state. |
| Layout families | Variant tags, and family pickers: a built-in choice or a component. |
| Dependencies | npm bundles, licences and allowed sites. |
| Render function | render(ctx), caching and photo metadata. |
| Rendered images | Async artwork for previews and export. |
| SVG maps | Vector tiles, projection and attribution. |
| Click-to-edit | Open parameter controls with ctx.edit(). |
| Anchors | Cross-references, pages and credits. |
| Editing UI | Generated controls and custom editors. |
| Element editors | React controls and parameter scopes. |
| Document editors | Book-wide parameter editors. |
| Editing on the page | Inline editor placement and styling. |
| File parameters | p.file, file() and imported assets. |
| Template findings | Report input problems with issue(). |
| Geometry helpers | Insets, grids and design coordinates. |
| Platform components | Spread, boxes, Element, Text and Caption. |
| CSS contract | Fonts, CSS variables, language and hyphenation, and print styling. |
| Validation | Template load and render checks. |
| Stored project data | Saved layouts, crops and parameters. |
| Authoring and compatibility details | SDK types, enum maps and preview limits. |
Inline plain text (inline-text) | Edit strings with ctx.Text, and photo captions with ctx.Caption, on the page. |
Formatted text (formatted-text) | Inline Markdown and FormattedText. |
Templates run code inside ImageFlow. Only open books and templates you trust.