Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Entity Render Context

Security covered Under active development 670 sites

Part of the Entity ecosystem · 308 projects

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.

Drupal 10–11

Ask your assistant about Entity Render Context

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

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
8 months ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Slowing

Releases

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