
A proposal: letting Canvas slots pass context from parent to child
A proposal, written after Canvas 1.0 and before 1.2, for letting a parent component pass structural context to the components placed in its slots.
A card placed inside a featured-article section in Drupal Canvas has no way to know it is there. It renders the same inside a featured grid as it does on its own, and any difference between the two has to come from somewhere other than the composition. This post is a proposal for closing that gap. I wrote it a month after Canvas 1.0.0 shipped on December 4, 2025, and nothing here describes a feature Canvas has.
How nesting works in Canvas today
Components nest in Canvas through slots. A component declares named slots in its metadata, and editors drag other components into them; the Canvas documentation describes a List component with an Items slot that accepts any other component as a list item. Props carry data into a component. Slots carry other components into it.
Nothing travels the other way, or downward past the slot boundary. A component in a slot receives its own props and nothing from the component that holds it.
What that costs
Take a featured-article section: a headline, an image, and a grid of article cards where the first card needs different treatment from the rest. Within the current model there are two ways to build it. Separate components for featured and supporting cards duplicate the markup. One card component with a “featured” prop works, but every editor has to set that prop by hand on the right card, and nothing stops it being set on the wrong one.
Neither option puts the knowledge where it belongs. The grid knows which position is featured. The card is the one that has to change.
What I’d want instead
A parent component would declare the context it provides to whatever lands in its slots, and a child would declare the context it can read. The keys below do not exist in SDC or Canvas metadata. They are the shape of the idea:
name: Featured Article Gridslots: items: title: Articlesprovides: context: featured_position: type: integer description: Index of the featured item within this slot (0 is featured).name: Cardaccepts: context: featured_position: type: integerIf a card declares context that the surrounding composition does not provide, Canvas could flag that while the page is being built, before anyone sees the result on the front end. The same mechanism would cover a section that sets a colour scheme for everything nested inside it.
Where I’d expect this to get hard
Optionality comes first. A component has to render with or without the context, so every accepts declaration needs a fallback. If the fallback is good enough, nobody will bother providing the context, and the declaration becomes dead weight.
Performance comes second. Context has to be threaded down the component tree at render time, and that cost should be measured before anyone relies on it for deep nesting.
Third, this covers structural context (“you are in the featured position”) and nothing data-driven (“render this only if the article has an event date”). That is a harder problem and I would keep it out of the composition layer.
I don’t know whether the Canvas maintainers want anything like this. Is there an existing pattern in the issue queue that handles slot context, and does it look like this or something else entirely?
What this came from
- ArticleCanvas project page
- ArticleCanvas documentation, SDC slots