Adding multiple links to the same table cell I am struggling to add multiple links to the same table cell, my current code looks like:

use Drupal\Core\Link;

$row[] = [
  'data' =&gt; Link::createFromRoute(...),
  'class' =&gt; 'middle',
];
$row[] = [
  'data' =&gt; Link::createFromRoute(...),
  'class' =&gt; 'middle',
];
$rows[] = ['data' =&gt; $row, 'no_striping' =&gt; TRUE];

return [
  '#theme' =&gt; 'table',
  '#header' =&gt; [..],
  '#rows' =&gt; $rows,
];


I've cut down the code to the relevant parts each element of the $row variable is a new cell and each element of the $rows variable is a new row. I need to use the data attribute as I have additional attributes on the cell.

At present this works perfectly fine, but my links are rendered in separate cells and I would like them rendered in the same cell. If I just to concatenate the 2 Link::createFromRoute I get the following error:

Recoverable fatal error: Object of class Drupal\Core\Link could not be converted to string

I've tried using the toString() and the toRenderable() functions and neither work as I want. Surely it can't be that hard?
I think you can do it as Clive alluded to with render array:

  $link_1 = Link::createFromRoute('Link 1', 'route_1')-&gt;toString();
  $link_2 = Link::createFromRoute('Link 2', 'route_2')-&gt;toString();
  $link_concat = ['#markup' =&gt; $link_1 . ' - ' . $link_2];

  $header = [ ... ];
  $row = [];
  $row[] = [
    'data' =&gt; \Drupal::service('renderer')-&gt;render($link_concat),
    'class' =&gt; 'middle',
  ];
return [
  '#theme' =&gt; 'table',
  '#header' =&gt; [..],
  '#rows' =&gt; $row,
];


This is just one method of doing it, there are a lot of ways you could potentially work this scenario. This way just puts the two links with a dash in between. But hopefully this will help guide you towards a solution.