Skip to content

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 ​

  1. Create a book from Photobook and open template/index.tsx in your editor. Included declarations and tsconfig.json provide type checking without installing packages.
  2. Read Package and Declaration.
  3. Adapt an example template. minimal.tsx is the smallest complete example. Examples use generic fonts; bundle fonts before print export.
  4. Use the Book check to catch layout and content issues.
  5. 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.

TopicWhat it covers
Authoring workflowMCP tools, revisions and drafts.
Project commands and preview targetsBatch edits, parameter scopes and previews.
PackageImports, examples and contract-1 features.
DeclarationdefineTemplate and layout builders.
Page layoutsPage roots, geometry and facing pages.
Parametersp.* types, options and defaults.
List parametersList items, IDs and edit commands.
Boxes and elementsPhoto boxes, Markdown flow, text.meta and composing a text.
Print formatTrim, bleed, safe areas and pagination.
Template libraryImport, previews and openingSpreads.
Switching layoutsContent, crops and saved layout state.
Layout familiesVariant tags, and family pickers: a built-in choice or a component.
Dependenciesnpm bundles, licences and allowed sites.
Render functionrender(ctx), caching and photo metadata.
Rendered imagesAsync artwork for previews and export.
SVG mapsVector tiles, projection and attribution.
Click-to-editOpen parameter controls with ctx.edit().
AnchorsCross-references, pages and credits.
Editing UIGenerated controls and custom editors.
Element editorsReact controls and parameter scopes.
Document editorsBook-wide parameter editors.
Editing on the pageInline editor placement and styling.
File parametersp.file, file() and imported assets.
Template findingsReport input problems with issue().
Geometry helpersInsets, grids and design coordinates.
Platform componentsSpread, boxes, Element, Text and Caption.
CSS contractFonts, CSS variables, language and hyphenation, and print styling.
ValidationTemplate load and render checks.
Stored project dataSaved layouts, crops and parameters.
Authoring and compatibility detailsSDK 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.