0

In EasyAdmin dashboard, i added a 'View website' link in the left menu:

enter image description here

But i would like it to open a new browser window on click. And I am wondering how to add a target="_blank" attribute to it (or any other solution to get this result).

For now i have this code in App\Controller\Admin\DashboardController.php:

public function configureMenuItems(): iterable
{
    yield MenuItem::linkToDashboard('Dashboard', 'fas fa-tachometer-alt');
    yield MenuItem::linkToUrl('View website', 'fas fa-eye', '/')
        ->setPermission('ROLE_ADMIN');
    // ...
}

Thank you!

Edouard
  • 363
  • 3
  • 14

3 Answers3

3
 yield MenuItem::linkToUrl('Homepage', 'fa fa-home', $this>generateUrl('homepage'))
        ->setLinkTarget(
            '_blanc'
        );
KrOvean
  • 41
  • 3
  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Jul 25 '22 at 10:25
1

You can try this

->setHtmlAttributes(['target' => '_blank'])

https://github.com/EasyCorp/EasyAdminBundle/blob/3.x/src/Config/Action.php

keuns76
  • 36
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 25 '22 at 18:52
0

It is now possible to use ->setLinkTarget(string $target);

It sets the target HTML attribute of the menu item link

From https://www.w3schools.com/tags/att_a_target.asp , here are the HTML options for a link :

<a target="_blank|_self|_parent|_top|framename">

For your case it would be :

  yield MenuItem::linkToUrl('View website', 'fas fa-eye', '/')
     ->setPermission('ROLE_ADMIN')
     ->setLinkTarget('_blank');
Toykato
  • 89
  • 5