You are here

public function TwigExtension::attachLibrary in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::attachLibrary()

Attaches an asset library to the template, and hence to the response.

Allows Twig templates to attach asset libraries using


{{ attach_library('extension/library_name') }}

Parameters

string $library: An asset library.

File

core/lib/Drupal/Core/Template/TwigExtension.php, line 358
Contains \Drupal\Core\Template\TwigExtension.

Class

TwigExtension
A class providing Drupal Twig extensions.

Namespace

Drupal\Core\Template

Code

public function attachLibrary($library) {

  // Use Renderer::render() on a temporary render array to get additional
  // bubbleable metadata on the render stack.
  $template_attached = [
    '#attached' => [
      'library' => [
        $library,
      ],
    ],
  ];
  $this->renderer
    ->render($template_attached);
}