Skip to content

Instantly share code, notes, and snippets.

@shelane
Created November 15, 2020 05:18
Show Gist options
  • Save shelane/63b5485ada126a76c76666432fd6190d to your computer and use it in GitHub Desktop.
Save shelane/63b5485ada126a76c76666432fd6190d to your computer and use it in GitHub Desktop.
t function variables
Including a link:
$link = Link::fromTextAndUrl($this->t('Bootstrap Documentation'), Url::fromUri('https://getbootstrap.com/docs/3.4/css/#grid-example-mixed-complete', ['attributes' => ['target' => '_blank']]))->toString();
'#description' => $this->t('When this option is selected, clearfix divs will be used to "clear" the columns as needed per device size (see %bootstrap_docs). Please note this option applies only when "Single row" is selected for the "Number of columns per view row" option.',
['%bootstrap_docs' => $link]),
The most common placeholder is probably @variable. This placeholder runs static::placeholderEscape() on the text before replacing it.
You may also use %variable, which runs placeholderEscape() on the text similar to @ placeholders. Using this placeholder will also create <em> tags around the placeholder values.
New in Drupal 8 is :variable, for use specifically with URLs. The :variable placeholder is escaped with \Drupal\Component\Utility\Html::escape() and filtered for dangerous protocols using UrlHelper::stripDangerousProtocols().
https://chromatichq.com/blog/drupal-code-standards-t-function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment