Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Varbase FAQs 9.2.1 Minor update available for module varbase_faqs (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

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.

Activity

Total releases
2
First release
Jan 2026
Latest release
5 months ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Releases

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