Add ability to modify icon attributes inside event #2276
-
Hi, I want create icon for my application that will be used in many places. This icon is like this <twig:ux:icon name="view" class="icon view" title="this item is public"/> So I dont want add title and class in many places, So I created EventListener like this: #[AsEventListener(priority: 100)]
class UxIconListener
{
public function __invoke(PreCreateForRenderEvent $event): void
{
if ('ux:icon' !== strtolower($event->getName())) {
return;
}
$attributes = $event->getInputProps();
if ($attributes['name']!=="view"){
return;
}
$attributes["class"] = "icon view";
$attributes["title"]= "this item is public";
//This is not possible yet
$event->setInputProps($attributes);
}
} Is this good way to do this? Or do you have some better solution? Of course this is only draft, it will be more sofisticated in finally. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Why don't you create a simple twig template (partial) with the icon, and include it where it is needed: {# _view_icon.html.twig #}
<twig:ux:icon name="view" class="icon view" title="this item is public"/> And in any other template: {# ... #}
{{ include('pah_to/_view.icon.htwml.twig') }}
{# ... #} |
Beta Was this translation helpful? Give feedback.
-
How I can do this with PreRenderEvent |
Beta Was this translation helpful? Give feedback.
How I can do this with PreRenderEvent