Includes
Includes let you share HTML fragments across pages. Store reusable markup in partial files and pull them in at build time -- headers, footers, <head> metadata, and anything else you repeat.
Creating an include
Create an HTML file anywhere in src/. A common convention is src/includes/:
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/assets/css/main.css">
Using includes
data-include attribute
Add data-include to any element. The element is replaced with the file content:
<!doctype html><html lang="en"><head> <meta data-include="/includes/head.html"> <title>Home</title></head><body> <header data-include="/includes/header.html"></header> <main>Content here</main> <footer data-include="/includes/footer.html"></footer></body></html>
include-file element
Use the <include-file> custom element for a more explicit syntax:
<include-file src="/includes/header.html"></include-file>
Both syntaxes produce the same result. The element is fully replaced with the contents of the referenced file.
Self-closing meta includes
For <head> content, <meta data-include> is especially useful since it is valid HTML in <head>:
<head> <meta data-include="/includes/head.html"> <title>Cook SSG</title></head>
File paths
Include paths are relative to src/. You can omit the .html extension -- Cook adds it automatically if missing:
<meta data-include="/includes/head.html"><meta data-include="/includes/head">
Nested includes
Included files can themselves contain includes. Cook resolves them iteratively up to 5 levels deep, which prevents infinite recursion while supporting practical nesting:
<header> <nav data-include="/includes/nav.html"></nav> <div data-include="/includes/search-bar.html"></div></header>
Caching
Cook caches include file content in memory during the build. If the same include is used across 50 pages, the file is read from disk once and served from the cache for subsequent uses. This makes includes fast even when shared across a large site.
Template strings in includes
Include files can contain ${variableName} template strings. Since includes are resolved before the final template string pass, your variables will be replaced after the include content is inlined into the page:
<footer> <p>© 2026 Cook SSG</p> <a href="${site.url}">${site.title}</a></footer>
Build-only directories
Include directories like src/includes/ are typically listed in buildOnlyPaths so they are used during the build but not copied to the output:
export default { buildOnlyPaths: ['includes', 'layouts'],};
Pipeline order
Includes are resolved early in the build pipeline -- after layout templates are applied but before data-repeat, components, and template strings. This means:
- Layout templates can contain includes
- Includes can contain components and template strings
- Includes can contain other includes (up to 5 levels)
- Includes cannot use data-repeat (repeat runs after includes)