There's one important detail about how components access data: Nunjucks macro scope isolation.
When section components are rendered via {% include %} statements inside a macro, template-level variables like data aren't automatically available. The solution is a context object that explicitly passes required data through the render chain.
How it works in sections-renderer.njk:
{# Build context object with all data needed by components #}
{% set context = {
data: data,
collections: collections,
collection: collection,
urlPath: urlPath,
crumbs: navigation.breadcrumbs
} %}
{% for section in sections %}
{{ renderSection(section, context) }}
{% endfor %}
Then in render-section.njk:
{% macro renderSection(section, context) %}
{# Extract context properties for use in included templates #}
{% set data = context.data %}
{% set collections = context.collections %}
{% set urlPath = context.urlPath %}
{% include "components/sections/" + section.sectionType + "/" + section.sectionType + ".njk" ignore missing %}
{% endmacro %}
This pattern makes data flow explicit and keeps components portable. The same component works in Metalsmith, Eleventy, or any SSG that implements the same context interface.
Which components need context?
Check each component's manifest.json for a context array:
{
"name": "podcast",
"type": "section",
"context": ["data.podcasts"],
"requires": ["ctas", "commons"]
}
Components without a context field are self-contained and only need their frontmatter section data. Components with context requirements need those properties passed through the render chain.
Context Properties Reference
Data Properties - These access external JSON data files:
| Property | Used by | Description |
|---|
data.artworks | artist-slider | Artwork metadata for slider |
data.author | blog-author | Author profiles |
data.blurbs | blurbs | Blurb content blocks |
data.calendars | calendar | Calendar configurations |
data.languages | header, language-switcher | Language switcher config |
data.maps | maps | Map configurations |
data.podcasts | podcast | Podcast feed configurations |
data.pricing | pricing-table | Pricing tier data |
data.team | team-grid | Team member profiles |
Site Properties - These provide site-wide or page-specific information:
| Property | Used by | Description |
|---|
collections | collection-list, compound | Named content collections |
collection | collection-links | Current page's collection info (prev/next) |
crumbs | breadcrumbs | Breadcrumb trail array |
urlPath | compound, header, navigation | Current page URL path |
Adding Context for New Components
When you install a component that requires context:
- Check the component's
manifest.json for a context array - Ensure your
sections-renderer.njk includes that property in the context object - Ensure your
render-section.njk extracts it before the {% include %}
Most components are self-contained and work out of the box without any context configuration. Components like text-only, hero, accordion, banner, cards-list, and most partials only need their frontmatter section data.