ux
ux copied to clipboard
[Live] Support for "originating" request object
Right now, using the {{ app.request }} variable inside a live component template or descendents returns the Request object for the ux_live_component route.
While this makes sense, it was a problem for my trying to generate urls that actually work as intendend.
As a workaround, I pass the route name and query for url generation as live prop and updated the template as follows:
<a href="{{ path(originalRoute ?? app.request.get('_route'), (originalQuery ?? app.request.query.all)|merge({page: pagination.previousPage})) }}">Go To Page {{ pagination.previousPage }}</a>
Because I re-use this template in both live components and classic controllers, I needed to use the null coalesce operation originalRoute ?? app.request.get('_route'). But I don't like it and it is easy to forget updating them when introducing Live components.
So maybe it would be possible to override and set the {{ app.request }} variable to the originating request (where originating = where the {{ component () }} was rendered)?
Hi there!
Can you say a bit more about why you need the original route name? Are you trying to generate a url to whatever “page” you’re currently on including the existing query params?
I think overriding app.request is a no go, but if we can dig into what you want to accomplish, we can find a nice solution.
Can you say a bit more about why you need the original route name? Are you trying to generate a url to whatever “page” you’re currently on including the existing query params?
That's exactly the use case I have! :)
In my example, the route name is dynamic (current page) so I cannot hardcode it because I reuse that particular template. Here, I am using a pagination template.
That's exactly the use case I have! :)
That makes sense! Though, I don't have a clever idea at the moment for how to support this. What are the other query parameters that may be already on the URL? I'm curious is they are LiveProps or something unrelated to the live component.
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
related: #1303
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
Friendly reminder that this issue exists. If I don't hear anything I'll close this.
Hey,
I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!