Same name and namespace in other branches
  1. 7.x includes/common.inc \render()
  2. 8.9.x core/includes/common.inc \render()

Renders an element.

This function renders an element. The top level element is shown with show() before rendering, so it will always be rendered even if hide() had been previously used on it.

Parameters

$element: The element to be rendered.

Return value

\Drupal\Component\Render\MarkupInterface|null The rendered element.

Deprecated

in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\RendererInterface::render() instead.

See also

https://www.drupal.org/node/2939099

\Drupal\Core\Render\RendererInterface

show()

hide()

1 call to render()
RenderDeprecationController::buildRenderFunction in core/modules/system/tests/modules/render_deprecation/src/RenderDeprecationController.php
47 string references to 'render'
AjaxResponseTest::testCommands in core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php
Tests the add and getCommands method.
AjaxTestController::getRenderTypes in core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php
Render types.
AjaxTestController::renderTypes in core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php
Example content for testing the wrapper of the response.
BlockTest::testBlockCacheTags in core/modules/block/tests/src/Functional/BlockTest.php
Tests that cache tags are properly set and bubbled up to the page cache.
BreadcrumbFrontCacheContextsTest::setUp in core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php

... See full list

File

core/includes/common.inc, line 397
Common functions that many Drupal modules will need to reference.

Code

function render(&$element) {
  @trigger_error('The render() function is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \\Drupal\\Core\\Render\\RendererInterface::render() instead. See https://www.drupal.org/node/2939099', E_USER_DEPRECATED);
  if (!$element && $element !== 0) {
    return NULL;
  }
  if (is_array($element)) {

    // Early return if this element was pre-rendered (no need to re-render).
    if (isset($element['#printed']) && $element['#printed'] == TRUE && isset($element['#markup']) && strlen($element['#markup']) > 0) {
      return $element['#markup'];
    }
    show($element);
    return \Drupal::service('renderer')
      ->render($element);
  }
  else {

    // Safe-guard for inappropriate use of render() on flat variables: return
    // the variable as-is.
    return $element;
  }
}