Document with pattern matching routing alias

I have a document at a route https://domain.com/path/to/document. I want to supply some in information in a modal on page load if some parameters are loaded in the url. But I want it to be a normal path url/ https://domain.com/path/to/document/:object/:id. So when the document loads and the extra object & id parameters are on the end of the url my javascript will pick it up and load the appropriate data in a modal.

Looking at the URLs based on Documents and Pretty URLs page I didn’t see if you could add patern matching in there to match an object and id in my url.

The Custom Routes seem to allow you to just push to controller/action and not be an alias for a document.

Was just wondering if this is possible in the admin or do I need to write a custom controller/action to grab the document I want and display and load it that way.

Thanks for any help.

Have you considered using URL parameters?

/path/to/document?object=N&id=N

Create a Controller and Action, in the view, do the same as with a normal content page.

Also create a Static Route, that points to the new Controller. If certain params are supplied to the Action, do your thing, if not, do nothing and just render the content. That’s basically it.

Thanks, I probably would of done that as default but these urls need to be shareable so I wanted to go with the non param route.

I ended up adding a route in a routing.yml that pointed to a controller/action. Then in the action I queried the document I wanted as the base and then rendered from there with my route params attached. It does what I needed but with 2 things I don’t really want hard coded.

I had to hardcode the document path for the query.
$document = Document::getByPath('/document/path');

Then I had to hardcode the render
return $this->render('@bundle/folder/view', ['document' => $document, 'editmode' => false]);

Not sure if I could of got that render path from the $document object or not though.