Drupal is a registered trademark of Dries Buytaert

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
2 weeks ago
Release cadence
12 days
Stability
50% stable

Releases

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