This project is not covered by Drupal’s security advisory policy.
Display Mode Switcher lets you show different field layouts to different audiences - no templates, no custom code, just configuration.
The classic use case is a paywall: anonymous visitors see a teaser or locked version of content, while subscribers see the full article. But the module works for any scenario where different users (or different contexts) should see a different arrangement of fields.
You define rules that specify: which entity and display mode you are starting from, which display mode to switch to, and what conditions must be true for the switch to happen. At render time the module evaluates your rules in order, picks the first match, and swaps the display mode transparently. If no rule matches, the original display mode is used unchanged.
Drupal's render cache is fully respected: cache metadata from every evaluated condition is propagated to the rendered output automatically.
Features
- Switch any entity's view mode at render time based on configurable rules - no template overrides needed.
- Rule-based evaluation with weight-ordered priority: the first matching rule wins, making it easy to build subscriber/anonymous/admin hierarchies.
- Ships with a User has role condition out of the box. All standard Drupal core condition plugins (node type, language, request path, current theme) work automatically.
- Any contrib module that provides condition plugins is supported automatically - no extra wiring.
- Custom condition plugins can be added by any module via a simple PHP class and a config schema entry.
- Conditions receive the entity being rendered directly, so field-level checks (e.g. "is this node marked as paywalled?") require no Context API setup.
- Cache tags, cache contexts, and max-age from all evaluated conditions are merged into the render array automatically.
- Rules are standard configuration entities: fully exportable, deployable via
drush config:export/import, and version-controllable. - A single permission (
administer display mode switcher) controls access to rule management.
Post-Installation
After enabling the module:
-
Create the view mode you want to switch to. Go to Structure → Display modes → View modes, add a new view mode for your
entity type (e.g.paywall), then go to the entity type's Manage display page, enable the new view mode under Custom display
settings, and configure which fields it shows. -
Create a rule. Go to Structure → Display modes → View modes → Switcher rules
(/admin/structure/display-modes/view/switcher) and click Add rule. Choose the entity type and (optionally) bundle, set the source
display mode that triggers evaluation (e.g.full), set the target display mode to switch to (e.g.paywall), and add one or
more conditions. A rule with no conditions always matches — useful as a catch-all fallback at a high weight. -
Test. Render the entity in the source display mode as a user who meets the conditions and verify the correct display mode appears.
Then test as a user who does not meet the conditions.
No database updates are needed. All configuration lives in YAML files and can be managed with Config Management (drush config:export).
Additional Requirements
- Drupal 11.3 or later
- No additional module dependencies beyond Drupal core.
Similar projects
- View Mode Page - serves an entity under a custom URL using a specific view mode,
rather than switching modes conditionally at render time. - Display Suite - powerful field layout builder that works well alongside this module; it does not provide rule-based mode switching.
- Content Access / href="https://www.drupal.org/project/permissions_by_term">Permissions by Term - restrict access entirely rather than showing a degraded view to unauthorised users. Use Display Mode Switcher when you want a teaser or locked layout instead of an access denied page.
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.- Project categories: Content display
- Created by zaporylie on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
