You are here

public function TwigExtension::tokenReplaceFilter in Twig Tweak 8.2

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

Replaces all tokens in a given string with appropriate values.

Parameters

string $text: An HTML string containing replaceable tokens.

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 entered HTML text with tokens replaced.

File

src/TwigExtension.php, line 1032

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

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