Table of Contents
Page context
A normalised per-page object: one cached snapshot of the values Baseline's modules need, built once during the data cascade and read again at transform-time without re-deriving from raw cascade data.
You access it as _pageContext in templates. Internally, the head module reads it through a registry lookup so the same object is available after the cascade has closed.
Why it exists
Eleventy's HTML transformer hook (where head injection runs) only sees page metadata. The data cascade is not available there. The page-context registry caches the cascade-time view so transform-time consumers can read it back by page.url. That trick is the difference between Baseline's head module being able to compose <title> from cascade data and it having to re-walk the cascade per request.
Where it surfaces
- In templates: as
_pageContext(computed viaeleventyComputed). - In
_snapshot: every built page-context lives under_snapshot.pageContext, keyed by URL. See Globals. - At transform-time: read by the head module via the registry's
getByKey(page.url)lookup.
The Page Context shape
Seven top-level keys. Each one is built by a small pure function from cascade data; the field itself is what the consumer sees.
| Key | What it carries | Built from |
|---|---|---|
site |
title, tagline, url, noindex. Per-language title/tagline if the page has a lang and settings.languages.<lang> overrides. |
settings, data.settings, page.lang |
page |
Eleventy's page snapshot, scoped to the keys baseline reads (url, inputPath, fileSlug, lang, locale, date, …). |
data.page |
entry |
Front-matter values: title, description, head. Page-level overrides for site defaults. |
data.title, data.description, data.head |
query |
Cheap derived flags. Today: isHome (true when page.url === '/'). |
entry, page |
meta |
Composed <title>, default description, canonical, robots, noindex. Title composition uses head.titleSeparator. |
data, site, page, query |
render |
Render-environment values. Today: generator (Eleventy's version string, when present). |
data.eleventy.generator |
head |
Merged + deduplicated link, script, style, meta arrays from settings.head and page front matter. Dedupe keys: href, src, href, name. |
settings.head, data.head |
Opt out: _internal: true
Templates that set _internal: true in their data are skipped by the registry. Pages with a non-HTML output extension are also skipped automatically.
This is for synthetic templates that should not get a page context: sitemap XML, the navigator debug page, any virtual template you write yourself that does not represent a real page. Set _internal: true in the template's data and the registry leaves it alone.
// In a virtual template's data
eleventyConfig.addTemplate('navigator-core.html', virtualTemplateContent, {
// ... other template settings,
permalink: '/feed.xml',
_internal: true
});
See also
- Globals -
_pageContextand_snapshot.pageContext. - Internals - the registry primitive that backs the cache.
- Head module - the consumer side; reads
_pageContextat transform-time. - Site settings - the inputs
siteandheadare built from.
Previous: Config export
Next: Internals