You are here

public function TwigExtension::getUrl 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::getUrl()

Generates an absolute URL given a route name and parameters.

@todo Add an option for scheme-relative URLs.

Parameters

$name: The name of the route.

array $parameters: An associative array of route parameter names and values.

array $options: (optional) An associative array of additional options. The 'absolute' option is forced to be TRUE.

Return value

string The generated absolute URL for the given route.

File

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

Class

TwigExtension
A class providing Drupal Twig extensions.

Namespace

Drupal\Core\Template

Code

public function getUrl($name, $parameters = array(), $options = array()) {

  // Generate URL.
  $options['absolute'] = TRUE;
  $generated_url = $this->urlGenerator
    ->generateFromRoute($name, $parameters, $options, TRUE);

  // Return as render array, so we can bubble the bubbleable metadata.
  $build = [
    '#markup' => $generated_url
      ->getGeneratedUrl(),
  ];
  $generated_url
    ->applyTo($build);
  return $build;
}