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}:
export default { siteTitle: 'Trail Maps', tagline: 'Navigate every peak',};
<h1>Cook SSG</h1><p>${tagline}</p>
The output replaces each variable with its value:
Nested property access
Use dot notation to access nested objects from your data:
export default { site: { title: 'Trail Maps', url: '<a href="https://trailmaps.co">https://trailmaps.co</a>', }, author: { name: 'Alex Chen', email: '<a href="mailto:alex@trailmaps.co">alex@trailmaps.co</a>', },};
<title>${site.title}</title><p>Created by ${author.name}</p>
Data sources
Template strings resolve from multiple sources, merged in this order (later sources win):
- Global data -- values from
config/data.js - Front matter -- YAML metadata at the top of Markdown or HTML files
src/docs/setup.md
---title: Setup Guideauthor: Alex Chen
---title: Setup Guideauthor: Alex Chen
${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:
<div class="alert alert-${type}"> <strong>${heading}</strong> ${slot}</div>
<alert type="warning" heading="Caution"> Trail closed due to weather.</alert>
Resolution order
Cook resolves template strings in a specific pipeline order during the build:
- Layout templates are applied, wrapping content in a shared shell
- Includes are resolved, pulling in partial HTML files
- Data-repeat expands elements for each item in an array
- Components expand custom elements, resolving their own
${attribute}variables - 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.