You are here

public function TwigExtension::with in Twig Tweak 8.2

Adds new element to the array.

Parameters

array $build: The renderable array to add the child item.

mixed $key: The key of the new element.

mixed $element: The element to add.

Return value

array The modified array.

File

src/TwigExtension.php, line 1164

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function with(array $build, $key, $element) {
  if (is_array($key)) {
    NestedArray::setValue($build, $key, $element);
  }
  else {
    $build[$key] = $element;
  }
  return $build;
}