1

Is it possible to include forward slashes in routing parameters?

// routing.yml
mymodule.route
    path: '/mymodule/{param}'
    defaults:
        path: ''
    requirements
        path: '[A-Za-z0-9\-\/]+'

/mymodule/this/is/a/single/param would then result in

$param = 'this/is/a/single/param';

being passed into the controller method.

1

I tested this out, and it doesn't work in Drupal 8, unfortunately.

mymodule.test:
  path: '/mymodule/{testparam}'
  defaults:
    _controller: '\Drupal\mymodule\Controller\TestController::build'
    _title: 'Variable Parameter'
  requirements:
    _permission: 'access content'
    testparam: .+

It picks up the route with "/mymodule/hello", but not "/mymodule/hello/world".

There's some more discussion of this here: Slashes in single route parameter or other ways to handle a menu tail with dynamic number of params

It looks like there's a solution, but it's pretty heavy handed.

  • drupal.stackexchange.com/a/187497/57167 doesn't look too bad! – Tim Jun 8 '16 at 14:52
  • You could easily add a parameter with alternate separator. /mymodule/arg1:arg2:arg3:arg4:arg5:arg6 – oknate Jun 8 '16 at 14:55
  • Yeah, @Tim, I guess it doesn't. I haven't tried it out though. I'm surprised they don't add this. Hopefully, in Drupal 9 they will. – oknate Jun 8 '16 at 14:56
  • 1
    Symfony supports it, they manually removed the option in drupal 8.0-beta-14 – Eyal Jun 8 '16 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.