add popups window with link I want to build popups in Drupal 8. This is the code I am using.

$attr = array(
 'attributes' =&gt; [
   'class' =&gt; ['use-ajax'],
   'data-dialog-type' =&gt; 'modal',
   'data-dialog-options' =&gt; Json::encode([
     'width' =&gt; 700,
   ]),
 ]
);
$url = Url::fromRoute('resume.grade_detail', ['uid' =&gt; $id, 'courseid' =&gt; $courseid]);
$internal_link = \Drupal::l($average, $url, $attr);

return array('#markup =&gt; $internal_link);


In the rendered output, i don't find the CSS classes I added; as result, the popup doesn't work.

I need help.
The markup element strips some HTML tags from the output. It is much better to just use the following code.

$attr = [
 'attributes' =&gt; [
   'class' =&gt; ['use-ajax'],
   'data-dialog-type' =&gt; 'modal',
   'data-dialog-options' =&gt; Json::encode([
     'width' =&gt; 700,
   ]),
 ]
];
$link = Link::createFromRoute($average, 'resume.grade_detail', ['uid' =&gt; $id, 'courseid' =&gt; $courseid], $attr);

return $link-&gt;toRenderable();