You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application where it would be nice to modify the URL before rendering.
In my case, I want to change the URL based on the current request. E.g. if the user visits company.net I want to get the assets from media.company.net, and if the user visits shop.com, I want to get the assets from media.shop.com.
So far added my own twig functions that override the behavior of the default {{ encore_entry_script_tags }} and {{ encore_entry_style_tags }}, but I don't like that a lot.
Version 1.9.0 gave me an idea: What if we allowed to set a new URL to the RenderAssetTagEvent?
E.g. something like this:
<?phpdeclare(strict_types=1);
namespaceApp\EventSubscriber;
useSymfony\Component\EventDispatcher\EventSubscriberInterface;
useSymfony\WebpackEncoreBundle\Event\RenderAssetTagEvent;
classEncoreTagSubscriberimplementsEventSubscriberInterface
{
publicstaticfunctiongetSubscribedEvents()
{
return [
RenderAssetTagEvent::class => 'onRenderAssetTag'
];
}
publicfunctiononRenderAssetTag(RenderAssetTagEvent$event)
{
// change URL according to our business logic$event->setUrl(str_replace('example.TLD', 'example.com', $event->getUrl()));
}
}
This actually works like this, but it feels wrong and I need to set either src or href depending on type:
Would you be interested in a PR that adds the RenderAssetTagEvent::setUrl method? Or is my $event->setAttribute('src', ...); workaround okay and future proof?
The text was updated successfully, but these errors were encountered:
I have an application where it would be nice to modify the URL before rendering.
In my case, I want to change the URL based on the current request. E.g. if the user visits company.net I want to get the assets from
media.company.net
, and if the user visitsshop.com
, I want to get the assets frommedia.shop.com
.So far added my own twig functions that override the behavior of the default
{{ encore_entry_script_tags }}
and{{ encore_entry_style_tags }}
, but I don't like that a lot.Version 1.9.0 gave me an idea: What if we allowed to set a new URL to the
RenderAssetTagEvent
?E.g. something like this:
This actually works like this, but it feels wrong and I need to set either
src
orhref
depending on type:Would you be interested in a PR that adds the
RenderAssetTagEvent::setUrl
method? Or is my$event->setAttribute('src', ...);
workaround okay and future proof?The text was updated successfully, but these errors were encountered: