function render

Same name in other branches
  1. 7.x includes/common.inc \render()
  2. 9 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

The rendered element.

See also

\Drupal\Core\Render\RendererInterface

show()

hide()

3 calls to render()
EntityField::render_item in core/modules/views/src/Plugin/views/field/EntityField.php
Renders a single item of a row.
shortcut_preprocess_page_title in core/modules/shortcut/shortcut.module
Implements hook_preprocess_HOOK() for page title templates.
template_preprocess_file_widget_multiple in core/modules/file/file.field.inc
Prepares variables for multi file form widget templates.
20 string references to 'render'
Attachment::buildOptionsForm in core/modules/views/src/Plugin/views/display/Attachment.php
Provide the default form for setting options.
CacheFactoryTest::testCacheFactoryWithCustomizedDefaultBackend in core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php
Test that the cache factory falls back to customized default service.
CacheFactoryTest::testCacheFactoryWithDefaultBinBackend in core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php
Test that the cache factory uses the correct default bin backend.
CacheFactoryTest::testCacheFactoryWithDefaultSettings in core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php
Test that the cache factory falls back to the built-in default service.
CacheFactoryTest::testCacheFactoryWithSpecifiedPerBinBackend in core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php
Test that the cache factory picks the correct per-bin service.

... See full list

File

core/includes/common.inc, line 865

Code

function render(&$element) {
    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;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.