Forum

Thread tagged as: Problem, Runway

Runway route matching

Hi,

I have a products page that lists product categories. Clicking a category takes you to a page that lists all products in that category. Clicking any of those products takes you to a product detail page.

The current routes are as follows:

products/[slug:cat]
product/[slug:slug]

This all works, but I have had a request to change things so that all of the pages are /products/category or /products/product

If i change the "product/[slug:slug]" to "products/[slug:slug]" I run in to route matching order issues. Whichever order they are in one of the routes doesn't work as they are both matching.

Is there a way round this?

Perch Runway: 3.0.14, PHP: 7.0.16-3+deb.sury.org~trusty+1, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $, with PDO
Server OS: Linux, apache2handler
Installed apps: content (3.0.14), assets (3.0.14), categories (3.0.14), perch_forms (1.10)
App runtimes: <?php $apps_list = [ 'perch_forms', ];
PERCH_LOGINPATH: /admin
PERCH_PATH: /var/www/abc.co.uk/admin
PERCH_CORE: /var/www/abc.co.uk/admin/core
PERCH_RESFILEPATH: /var/www/abc.co.uk/admin/resources
Image manipulation: GD
PHP limits: Max upload 2M, Max POST 8M, Memory: 128M, Total max file upload: 2M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: abc.test
DOCUMENT_ROOT: /var/www/abc.co.uk
REQUEST_URI: /admin/core/settings/diagnostics/
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
Andy Knight

Andy Knight 1 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't tell the difference from the URL, so you'll have to route them to the same place and then change behaviour based on the data. Check to see if the slug is a product slug - if it is, it's a product page. If not, it's a category page.

Thanks Hussein/Drew,

Makes sense but how would I check to see if its a product slug or category slug in the route?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

If you're using products/[slug:slug] and your pages are products/category and products/product, I think something like this might work:

if (perch_get('slug')) {
    $product = perch_shop_product(perch_get('slug'), [], true);

    if($product) {
        echo $product;
    } else {
        // perch_get('slug') is a category slug
    }

}