TwigExtension::getUrl

public TwigExtension::getUrl($name, $parameters = array(), $options = array())

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 240

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

Please login to continue.