You are here

function twig_without in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/themes/engines/twig/twig.engine \twig_without()

Removes child elements from a copy of the original array.

Creates a copy of the renderable array and removes child elements by key specified through filter's arguments. The copy can be printed without these elements. The original renderable array is still available and can be used to print child elements in their entirety in the twig template.

Parameters

array|object $element: The parent renderable array to exclude the child items.

string[] $args, ...: The string keys of $element to prevent printing.

Return value

array The filtered renderable array.

1 string reference to 'twig_without'
TwigExtension::getFilters in core/lib/Drupal/Core/Template/TwigExtension.php

File

core/themes/engines/twig/twig.engine, line 137
Handles integration of Twig templates with the Drupal theme system.

Code

function twig_without($element) {
  if ($element instanceof ArrayAccess) {
    $filtered_element = clone $element;
  }
  else {
    $filtered_element = $element;
  }
  $args = func_get_args();
  unset($args[0]);
  foreach ($args as $arg) {
    if (isset($filtered_element[$arg])) {
      unset($filtered_element[$arg]);
    }
  }
  return $filtered_element;
}