You create a custom controller and want to show a table that resembles the core back-end tables. This snippet shows you how to do it.

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)

The result looks like this:

Render a table with html in drupal 8





Saved you some valuable time?


Donate and get more free time-saving code on this website in the future.