FormattableMarkup : Add parameters, links to a text, table cell data. | Drupal 8

FormattableMarkup : Add parameters, links to a text, table cell data.

Submitted by editor on Mon, 01/22/2018 - 12:15
Question

How to create a  dynamic text to add a parameter or link ?
How to add a link to a table particular column ?

Create a customizable text.

Example :
use Drupal\Component\Render\FormattableMarkup;
$text = new FormattableMarkup('My name is @name', ['@name' => "The name"]);

Theme table row to link particular column data.

Example:
use Drupal\Component\Render\FormattableMarkup;
$rows[] = [
'data' => [
  'name' => new FormattableMarkup('<a href=":link">@name</a>', [':link' => $url, '@name' => $name]),
  'mail' => $row->mail,
]];

Add new comment