You are here

public static function TwigTweakExtension::drupalToken in Twig Tweak 3.x

Same name and namespace in other branches
  1. 3.1.x src/TwigTweakExtension.php \Drupal\twig_tweak\TwigTweakExtension::drupalToken()

Replaces a given token 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/TwigTweakExtension.php, line 276

Class

TwigTweakExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

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