Drupal is a registered trademark of Dries Buytaert

Overview

Node Role Variants allows you to serve different content to users based on their roles, similar to how content translations work for multilingual sites. This enables personalized content experiences where authenticated users, subscribers, or any custom role can see different versions of the same page.

Features

  • Role-Based Content Variants: Serve different node content based on user roles (anonymous, authenticated, custom roles).
  • Shared Path Mode: Keep the same URL for all variants - users see different content at the same path based on their role.
  • Separate Path Mode: Each variant has its own URL with automatic redirects based on user role.
  • Priority Weights: Control which variant takes precedence when a user has multiple roles.
  • Seamless Rendering: Variants render exactly like canonical nodes with proper template selection and view modes.
  • Cache-Aware: Properly integrates with Drupal's caching system using appropriate cache contexts and tags.
  • Admin Preview: Bypass role redirects with a query parameter for testing.
  • Theme Integration: Provides template suggestions for role-variant-specific theming.
  • Clone as Variant: Quickly create variant nodes by cloning the primary node, with full support for paragraph duplication.
  • UUID-Based Storage: Uses node UUIDs instead of IDs for cross-environment portability.

Use Cases

  • Personalized Homepages: Show different homepage content to anonymous vs authenticated users.
  • Membership Tiers: Display premium content to subscribers while showing teasers to free users.
  • Role-Specific Landing Pages: Create tailored experiences for different user groups (students, teachers, admins).
  • A/B Testing by Role: Test different content variations across user segments.

How It Works

Shared Path Mode (Default)

When enabled, all variants share the same URL path. Users visiting the primary node's URL will see content appropriate for their role without any redirect.

  • URL stays the same: /node/1 or /my-page
  • Content is swapped based on user role
  • Better for SEO and user experience
  • Ideal for personalized landing pages

Separate Paths Mode

When disabled, each variant maintains its own URL. Users are redirected to their appropriate variant.

  • Each variant has its own path
  • 302 redirects route users to correct variant
  • Useful when variants need distinct URLs
  • Good for tracking/analytics per role

Quick Start

1. Enable Role Variants for a Content Type

  1. Navigate to Administration > Structure > Content types.
  2. Edit the content type you want to enable role variants for.
  3. Expand the Role variants section.
  4. Check Enable role-based variants.
  5. Save the content type.

2. Create and Configure Variants

  1. Create or navigate to the primary node.
  2. Click the Role Variants tab.
  3. Choose a method: "Reference existing content" or "Clone this node".
  4. Select the role this variant applies to.
  5. Click Add variant.

3. Test Your Setup

  • Visit the page as different users to see the appropriate variant.
  • Add ?no-role-redirect=1 to bypass role switching for admin preview.

Caching

The module properly integrates with Drupal's cache system:

  • Cache Contexts: user.roles ensures pages are cached per role combination.
  • Cache Tags: Proper invalidation when nodes or variant configuration changes.
  • Dynamic Page Cache Compatible: Works correctly with Drupal's page caching.

Credits

Co-authored with Claude Code - AI pair programming assistant by Anthropic.

Activity

Total releases
2
First release
Dec 2025
Latest release
2 months ago
Release cadence
0 days
Stability
50% stable

Releases

Version Type Release date
1.0.x-dev Dev Dec 4, 2025
1.0.0 Stable Dec 4, 2025