I'm attempting to make a contenttype specific route, like the example in the bolt documentation:
pagebinding:
path: /{slug}
defaults:
_controller: 'Bolt\Controllers\Frontend::record'
'contenttypeslug': page
requirements:
'contenttypeslug': 'Bolt\Controllers\Routing::getAnyContentTypeRequirement'
But operating on multiple contenttypes ("pages" and "users" specifically).
In other words, I'd like to do something like this:
pagebinding:
path: /{slug}
defaults:
_controller: 'Bolt\Controllers\Frontend::record'
'contenttypeslug': page, user
requirements:
'contenttypeslug': 'Bolt\Controllers\Routing::getAnyContentTypeRequirement'
This particular example doesn't work, giving a 404 error when e.g. domain.tld/page, user/somepage
isn't found.
So that both domain.tld/somepage
and domain.tld/username
work,
assuming somepage
is the slug of a "page" record, and username
is the slug of a "user" record.
Is this possible?
Simple answer: You can't. There can be only one contenttype that has /{slug}
.
Say you have a user 'x', and a page 'x'. Somebody goes to 'domain.tld/x', there's no way to know which is which. Just make the users have a logical URL like /user/x
.