Forum
Analyze Routes in runway
In Runway, it is possible to define multiple routes per page. That is awesome. How do I work with those routes after a page is called?
What I want to do:
- Page has 3 routes: lorem1, lorem2 and lorem3
- When the page has been found, find out through which route token we have come in. Say it's "lorem2"
- Get an array of all defined routes in the order they were entered in the backend
- Then I would like to know which position the chosen token had in that list.
That's it. Drew, you might guess what I'm trying to achieve here
If you turn on debug you can see how the route has been matched. The components are available through
perch_get()
.I get the matched route
but not a list of all routes defined in the backend.
Later on the same page, I planned to filter content depending on the position of the selected route in the route list.
The goal of this is of course to edit one page with fields in multiple languages.
It just doesn't work like that. You don't get a list of routes that could've matched but didn't.
Is there a way to analyze a route and get a pattern from it? Maybe match it to a <perch:pages> field?
What are you trying to do?
I was trying to find out if a "single tree" structure with perch Pages is possible with existing on-board tools.
So I wanted to detect from the URL/route which language has been preselected.
Wich, having given it a little more thought, is not even necessary: Just add a language marker like /en/ to the URL and go from there.
But how do I handle that incoming route then? Say it's /en/aboutus and /de/ueberuns Hmmm, I could strip the first bit in .htaccess and store it in $_GET['lang'], and then send the rest of the URL This might also work with domains as indicators for the language.
What do you think about prepping a runway URL in that way?
Would it help if there was some way to configure a routing prefix globally?
If I can bring it into each navigation template via PerchSystem::set_var() and if it's safe to do some rewriting like the above before passing it to runway: I don't think that would be even necessary.
If it works then it's fine to do.
It doesn't. Probably due to my .htaccess skills. It's too early for me to ask you for the routing prefix, though, as I'm only doing this proof of concept style.
Just an idea: if in start.php instead of
you'd replace that by
And then in config.php
I (ehm, integrators...) could modify the value for PERCH_REQUEST_URI dynamically (e.g. with a simple str_replace).
Ok. Let me know how you get on.
Hmm.. getting on not too bad.
If the language is based on the domain, it should work, start.php uses the REQUEST_URI.
I will be using this approach and will post the working .htaccess later.
Albeit, with the prefix it's not so easy, as a Redirect (R) flag is necessary to alter the REQUEST_URI - which of course, results in a redirect, which we don't want.
So yes, maybe a global routing prefix would be a fine idea. Or, see my last post, allow developers to determine from where
$Router->get_route
gets its information (without hacking start.php)! That would be probably be the simpler way.Happy Holidays!