Template Strings

Cook replaces ${variableName} expressions in your HTML with values from your data at build time. No client-side JavaScript needed.

Basic usage

Define data in config/data.js and reference it with ${key}:

The output replaces each variable with its value:

<h1>Trail Maps</h1> <p>Navigate every peak</p>

Nested property access

Use dot notation to access nested objects from your data:

Data sources

Template strings resolve from multiple sources, merged in this order (later sources win):

  1. Global data -- values from config/data.js
  2. Front matter -- YAML metadata at the top of Markdown or HTML files

${title}

Written by ${author}

Front matter values override global data for that page. If config/data.js defines title: 'Trail Maps' but a page's front matter sets title: 'Setup Guide', the page uses Setup Guide.

Component attributes

Inside component templates, ${variableName} resolves from the attributes passed to the component. This is a separate resolution step -- components replace their own variables when they expand:

Resolution order

Cook resolves template strings in a specific pipeline order during the build:

  1. Layout templates are applied, wrapping content in a shared shell
  2. Includes are resolved, pulling in partial HTML files
  3. Data-repeat expands elements for each item in an array
  4. Components expand custom elements, resolving their own ${attribute} variables
  5. Final template strings are resolved across the fully assembled page using global data merged with front matter

This means an include file can contain Cook SSG and it will be resolved in step 5, after the include content has been inlined. Similarly, a repeated element can contain Cook SSG and it will resolve in the final pass.

Unresolved variables

If a ${variableName} has no matching data value, Cook leaves it in the output unchanged. This is intentional -- it prevents silent data loss and makes missing variables easy to spot. It also allows Vue-style ${{doublebraces}} to pass through untouched.

Protected contexts

Cook does not replace template strings inside <script> or <style> element content. JavaScript template literals and CSS custom properties are left untouched. However, template strings in attributes on those elements (like <script src="${site.js}">) are still resolved.

Supported file types

Template strings are resolved in .html, .json, and .webmanifest files. Other file types pass through the build unchanged.