Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Release: Change Requests 2.1.9 Minor update available for module change_requests (2.1.9). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Entity Render Context

304 sites Security covered Drupal 10–11 Entity ecosystem
View on drupal.org

This module provides a service to render Drupal entities with full control over the rendering context. You can specify the theme, user account, language, and view mode, which is useful for tasks like search indexing, static site generation, or generating API responses that require consistent output. It also includes caching and ensures the original rendering context is restored.

Entity Render Context provides a service for rendering Drupal entities with full control over the rendering context. It allows you to render any entity as HTML while specifying the theme, user account, language, and view mode — essential for scenarios such as search indexing, static site generation, or API responses that require consistent, context-independent output.

Features

  • Configurable theme: Render entities using any installed theme, not just the currently active one
  • User context control: Render as anonymous user or any specific account to ensure consistent access-based output
  • Multilanguage support: Render entities in any available language, regardless of the current request language
  • View mode support: Use any view mode (full, teaser, custom, etc.)
  • Internal caching: Request-scoped cache prevents redundant rendering of the same entity
  • Context restoration: Always restores original context (theme, user, language) even when errors occur
  • Revision aware: Cache keys include entity revision for accurate output on revisionable entities

Use cases:

  • Search indexing (render content as anonymous user in default theme)
  • Static site generation
  • Email notifications with rendered entity content
  • API responses that include rendered HTML
  • Background processing where rendering context differs from web requests

Usage

This module provides a service with no admin UI. After enabling, inject the entity_render_context.renderer service in your custom code:

// Basic usage (use dependency injection when possible instead)
  $service = \Drupal::service('entity_render_context.renderer');
  $html = $service->renderEntity($node);
                                                                                                                                                                                            
  // With all options
  $html = $service->renderEntity(
    entity: $node,
    viewMode: 'teaser',
    theme: 'your_theme',
    account: $user,
    langcode: 'de'
  );

  // Bulk rendering
  $htmlArray = $service->renderEntities($nodes, 'teaser');
  

No configuration pages are required. The service is immediately available after installation.

Similar projects

  • Entity Mesh: Provides similar rendering context functionality but includes additional features for entity synchronization. Entity Render Context is a lightweight alternative focused solely on rendering.
  • Search API: Includes internal rendering utilities for indexing. Entity Render Context extracts this pattern into a reusable, standalone service.

Documentation

See the README.md file included with the module for complete API documentation and usage examples.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

2 tracked projects depend on this one

Activity

Tracked releases
2
Tracked since
Jan 2026
Latest release
6 months ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Slowing

Releases

Version Type Core Release date
1.0.0 Stable 10–11 Feb 11, 2026
1.0.x-dev Dev 10–11 Jan 30, 2026