How can I add markup above the table in a custom module? I am working on a Drupal 8 custom module which renders pages as shown in the following image.



So far, I am able to build the table and my code is the following.

  public function dexp_layerslider_list() {
    $header = [
        'ID',
        'Name',
        'Action',
    ] ;
    $results = db_select('{dexp_layerslider}', 'd')-&gt;fields('d', [
        'id',
        'name',
    ])-&gt;execute();
    foreach ($results as $row) {
        $url = Url::fromUserInput("/admin/dexp_layerslider/". $row-&gt;id . "/edit");
        $row-&gt;name = (Link::fromTextAndUrl($row-&gt;name, $url));
        $editslides = Url::fromUserInput('/admin/dexp_layerslider/'.$row-&gt;id.'/editslides');
        $editslides_link = (Link::fromTextAndUrl('Edit slides', $editslides))-&gt;toString();
        $exportslides = Url::fromUserInput('/admin/dexp_layerslider/'. $row-&gt;id . '/export');
        $exportslides_link =  (Link::fromTextAndUrl('Export slides', $exportslides))-&gt;toString();
        $deleteslides = Url::fromUserInput('/admin/dexp_layerslider/'. $row-&gt;id . '/delete');
        $deleteslides_link =  (Link::fromTextAndUrl('Delete', $deleteslides))-&gt;toString();
     $tmp =  [
            '#type' =&gt; 'inline_template',
             '#template' =&gt; '{{ link1 |raw }}, {{ link2 | raw }}, {{ link3 | raw}}',
                '#context' =&gt; [
                         'link1' =&gt; $editslides_link-&gt;getGeneratedLink(),
                         'link2' =&gt; $exportslides_link-&gt;getGeneratedLink(),
                            'link3' =&gt; $deleteslides_link-&gt;getGeneratedLink(),
                            ]
                    ];
        // Row with attributes on the row and some of its cells.
     $rows[] = array(
            'data' =&gt; array($row-&gt;id,$row-&gt;name,$tmp )
                );
        }
     $table = array(
        '#type' =&gt; 'table',
        '#header' =&gt; $header,
        '#rows' =&gt; $rows,
        '#sticky' =&gt; FALSE,
        '#empty' =&gt; t('No slider created yet.'),
         );
        for($i= 0; $i
            $table['#rows'][$i]['data'][2] = $tmp;
        }
    return $table;
 }


How do I add a "Add slide" and "Export slide" links?
You have multiple solutions to achieve what you want


Using #prefix

 $table = array(
  '#prefix'=&gt; '&lt;div&gt;&lt;a&gt;my link&lt;/a&gt;&lt;/div&gt;',
  '#type' =&gt; 'table',
  '#header' =&gt; $header,
  '#rows' =&gt; $rows,
  '#sticky' =&gt; FALSE,
  '#empty' =&gt; t('No slider created yet.'),
 );
for($i= 0; $i
    $table['#rows'][$i]['data'][2] = $tmp;
}

A better way to do this is

 $table = array(
  'links' =&gt; [
     '#type'=&gt; 'container'
     'link_one'=&gt; [
        '#type' =&gt; 'link',
        '#title' =&gt; $this-&gt;t('Add slide'),
        '#url' =&gt; Url::fromRoute('my_route'),
      ],
   ],
  '#type' =&gt; 'table',
  '#header' =&gt; $header,
  '#rows' =&gt; $rows,
  '#sticky' =&gt; FALSE,
  '#empty' =&gt; t('No slider created yet.'),
 );
for($i= 0; $i
    $table['#rows'][$i]['data'][2] = $tmp;
}

Add module definied actions: https://www.drupal.org/docs/8/api/menu-api/providing-module-defined-actions