twig_without

twig_without($element)

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.

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;
}
doc_Drupal
2016-10-29 09:49:50
Comments
Leave a Comment

Please login to continue.