You are here

public function TwigExtension::drupalToken in Twig Tweak 8

Same name and namespace in other branches
  1. 8.2 src/TwigExtension.php \Drupal\twig_tweak\TwigExtension::drupalToken()

Replaces a given tokens with appropriate value.

Parameters

string $token: A replaceable token.

array $data: (optional) An array of keyed objects. For simple replacement scenarios 'node', 'user', and others are common keys, with an accompanying node or user object being the value. Some token types, like 'site', do not require any explicit information from $data and can be replaced even if it is empty.

array $options: (optional) A keyed array of settings and flags to control the token replacement process.

Return value

string The token value.

See also

\Drupal\Core\Utility\Token::replace()

File

src/TwigExtension.php, line 296

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function drupalToken($token, array $data = [], array $options = []) {
  return \Drupal::token()
    ->replace("[{$token}]", $data, $options);
}