Search code examples
phpsymfonyeasyadmineasyadmin3

How to make a target_blank Menu link in EasyAdminBundle?


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!


Solution

  • You can try this

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

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