Part of the Canvas ecosystem · 49 projects
Canvas Conditional Container adds a container component to Drupal Canvas. Components placed inside it are only rendered when the container's visibility rules evaluate to true. Content creators can show a promotion during a campaign, hide a sign-up prompt from logged-in users, or vary a section by path, without leaving the Canvas editor.
The first visibility provider is Context, so sites can reuse the same named, exportable conditions they already manage in Context. Visibility is defined through a plugin system, so other providers can be added over time.
Project status
The first phase of development is complete: the container component, the Context visibility provider, and server-side evaluation are all implemented. Testing and feedback from the community are very welcome. Please report bugs, rough edges and feature ideas in the issue queue. This project is still a sandbox, so don't use it on production sites yet.
Features
- A single container component with one slot for nested components.
- Reference one or more Contexts through an autocomplete, with an option to negate each one.
- Group references and combine them with AND/OR logic, within and between groups, similar to Views filter groups.
- An empty rule list always shows the nested content.
- References to deleted or disabled Contexts show a warning in the editor and hide the content on the live page.
- The editor preview always shows nested components, with a summary of the container's rules.
- Hidden content is never sent to the browser. With Twig debugging enabled, an HTML comment explains how each rule was evaluated.
- No wrapper markup is added when the content is visible.
- Containers render as placeholders, so visibility can vary per request without disabling caching for the rest of the page.
Requirements
Installation
Sandbox projects can't be installed with Composer. Clone the repository into your site's custom modules directory instead:
git clone https://git.drupalcode.org/sandbox/mandclu-3638397.git web/modules/custom/canvas_conditional_container drush en canvas_conditional_container
Then create one or more Contexts with the conditions you need, add a Conditional container in the Canvas editor, choose its Contexts, and place components in its slot. Note that If the site has an Administrator role (machine name `administrator`), the module also adds an example Context, Administrator (demo). It's active
when the current user has that role, so you can try a container without
setting up a Context first. Edit or delete it as you like.
A more robust demo can be quickly spun up using the Canvas Conditional Container Example recipe.
Help wanted with testing
Feedback is especially useful on:
- The editing experience: choosing Contexts, grouping them, and understanding the rules summary in the preview.
- Rule logic, including negation and combinations of AND/OR groups.
- Caching behavior with different cache setups, particularly for authenticated users and with BigPipe.
- Compatibility with different versions of Canvas and Context.
Caching considerations
Visibility is evaluated on the server for each request. Pages served to anonymous visitors from Drupal's Internal Page Cache, or from a CDN or reverse proxy, can't vary by conditions such as user role or session. For now, only conditions based on the URL are safe for fully cached anonymous pages. Later releases will explore pluggable edge-caching strategies and client-side evaluation.
Roadmap
- Phase 1 (complete): server-side evaluation, with Context as the visibility provider.
- Phase 2: editor refinements, including simulating conditions
Ask your assistant about Canvas Conditional Container
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the Canvas ecosystem
Most installed first
Activity
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 1.0.x-dev | Dev | 11 | Nov 21, 2026 |