Reputation: 403
In EasyAdmin dashboard, i added a 'View website' link in the left menu:
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!
Upvotes: 2
Views: 1101
Reputation: 119
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');
Upvotes: 1
Reputation: 56
You can try this
->setHtmlAttributes(['target' => '_blank'])
https://github.com/EasyCorp/EasyAdminBundle/blob/3.x/src/Config/Action.php
Upvotes: 3
Reputation: 66
yield MenuItem::linkToUrl('Homepage', 'fa fa-home', $this>generateUrl('homepage'))
->setLinkTarget(
'_blanc'
);
Upvotes: 4