0

I have a Drupal 8 website with a URL like http://mywebsite.com/my-content-url/my-content-url. What I have done is adding a variable to the URL, making it like http://mywebsite.com/my-content-url/my-content-url/myvariable.

How do I get Drupal 8 to stop seeing /myvariable as a part of the URL and giving me a 404 error?

2

You need a menu callback that accepts the variable. For more info, take a look at the Drupal docs.

Another way to do this is to pass your variable as a query parameter like http://mywebsite.com/my-content-url/my-content-url?var=myvariable. You can then use code to parse that parameter from the URL. You can get those parameters by using something like \Drupal::request()->query->all();

  • Thanks, I need the first one. So do I add it in my template.theme or do I need to create small module for this? – purencool Dec 9 '16 at 1:02
  • The correct way to do this is in a module. – lukedekker Dec 9 '16 at 19:45

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.