ux icon indicating copy to clipboard operation
ux copied to clipboard

[Live] Support for "originating" request object

Open richardhj opened this issue 2 years ago • 6 comments

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)?

richardhj avatar Jun 30 '23 22:06 richardhj

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.

weaverryan avatar Jul 01 '23 21:07 weaverryan

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.

richardhj avatar Jul 03 '23 08:07 richardhj

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.

weaverryan avatar Jul 05 '23 16:07 weaverryan

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Apr 25 '24 12:04 carsonbot

related: #1303

richardhj avatar Apr 25 '24 13:04 richardhj

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Oct 26 '24 12:10 carsonbot

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

carsonbot avatar Nov 09 '24 12:11 carsonbot

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!

carsonbot avatar Nov 23 '24 12:11 carsonbot