I have created a module with its routing.yml file.
mymodule.dossier:
path: '/dossiers/{node}/dossier'
defaults:
_entity_view: 'node.dossier_dossier'
requirements:
_permission: 'access content'
I have created a custom view mode (node.dossier_dossier) and the corresponding Twig template. If I go to dossiers/1/dossier, it works, and it displays the node with the dossier_dossier view mode and appropriate template.
node/1 has /dossiers/my-custom-path as its path alias, which is automatically set from the Pathauto module. If I try to access /dossiers/my-custom-path/dossier, it returns a Page not found error.
How can I make this route work for my nodes for both (default and path aliases) URLs?
Edit: I should maybe mention why I need that:
- /dossiers/my-custom-path should display the node using the default view mode
- /dossiers/my-custom-path/dossier should display the node using the dossier_dossier view mode
- /dossiers/my-custom-path/abstract should display the node using yet another view mode (I'd create another route for that one presumably)
/dossiers
part of the path, I also tried withpath: '/{node}/dossier'
but that didn't work either./dossiers/my-custom-path/dossier
to work, you have to use the complete url as alias.{node}
refers to the node's ID, which is then upcast to a node object for the controller. It doesn't refer to any URL alias you may have for the node. To get what you're looking for, you'd need a custom upcaster that searched for and found the node based on its alias