1

I've searched and searched for info on regex backreferences in Craft's route.php file to no avail.

I have a URL structure required by the client along the lines of:

/ [state] / [section] / region / [region]

so for examples:

/ hawaii / hotels / region / oahu
/ hawaii / retaurants / region / oahu
/ hawaii / hotels / region / maui

The "hotels" and "restaurants" are each their own Section (Channels) and require their own templates.

Given the above URL examples, I've created template directories:

/hotels/region.html
/restaurants/region.html

I can manage the routes if I spell them all out. But what I'd like to do is use regex backreferences in the target templates. Tried but it fails. tried something like the following:

'hawaii/(.*)/region' => '\1/region'

The '\1' backreference doesn't catch the first group of either "hotels" or "restaurants."

Is it simply not possible to use backrefs in the target route templates...or is my syntax not correct for Craft?

1 Answer 1

1

Is it simply not possible to use backrefs in the target route templates

Right now it's not possible (although might be worth a feature request).

The right hand side of the route key => value pair can currently only be a static string that is a path to the template to load or an array that defines a controller action to load.

1
  • Thanks @Brad! Assumed so but wanted to be sure it just didn't require a different syntax. And I'll def add a feature request. Commented Oct 12, 2016 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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