Skip to content

Instantly share code, notes, and snippets.

@manniru
Created May 8, 2022 08:46
Show Gist options
  • Select an option

  • Save manniru/ce6ad2c4c1bfb83282a59cf71e59e2d0 to your computer and use it in GitHub Desktop.

Select an option

Save manniru/ce6ad2c4c1bfb83282a59cf71e59e2d0 to your computer and use it in GitHub Desktop.
How to render a table in drupal 8 (with html in cells)
use Drupal\Core\Render\Markup;
$rows = [
[Markup::create('<strong>test 1</strong>'),'test'],
[Markup::create('<s>test 2</s>'), 'test'],
[Markup::create('<div>test 3</div>'), 'test'],
];
$header = [
'title' => t('Title'),
'content' => t('Content'),
];
$build['table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No content has been found.'),
];
return [
'#type' => '#markup',
'#markup' => render($build)
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment