We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question

Move date to end of blogslug?

Hi,

I'd like to move the date to the end of the blogslug, instead of it being at the start. Here's my setup.

runway.php

'routing_tokens' => [
    'blogslug' => '[1-2][0-9]{3}\-[0-9]{2}\-[0-3][0-9]-[a-z0-9\-]+',
],

Editing General Settings: Slug format

I've flipped the date, it's now at the end of the slug

{postTitle}-%Y-%m-%d

Editing ‘Post’ Page

news/[blogslug:s]/[preview:preview]
news/[blogslug:s]

The URL

"Sorry, that page could not be found."

news/demo-test-2018-06-23

I guess I need to edit the custom token in runway.php. I thought I could just flip the token order like this:

'routing_tokens' => [
            'blogslug' => '[a-z0-9\-]-[1-2][0-9]{3}\-[0-9]{2}\-[0-3][0-9]+',
],

But it doesn't work, has anyone done this?


Summary

Perch Runway: 3.1.1, PHP: 7.1.12, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO
Server OS: Darwin, cgi-fcgi
Installed apps: content (3.1.1), assets (3.1.1), categories (3.1.1), perch_blog (5.6.1), perch_forms (1.11)
App runtimes: <?php $apps_list = [ 'perch_forms', 'perch_blog'  ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/stephen/Repositories/project-name/cms/perch
PERCH_CORE: /Users/stephen/Repositories/project-name/cms/perch/core
PERCH_RESFILEPATH: /Users/stephen/Repositories/project-name/cms/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
REQUEST_URI: /perch/core/settings/diagnostics/
DOCUMENT_ROOT: /Users/stephen/Repositories/project-name/cms
HTTP_HOST: project-name.local
Stephen Meehan

Stephen Meehan 4 points

  • 9 months ago
Drew McLellan

Drew McLellan 2637 points
Perch Support

You may need to make the [a-z0-9\-] non greedy so that it doesn't swallow the rest of the string.

Thanks for the tip Drew.

I found this great tool to help me test the token

The token below matches theblogslug when the date is moved to the end of the slug

'blogslug' => '[a-z0-9\-]+-[1-2][0-9]{3}\-[0-9]{2}\-[0-3][0-9]+',

I needed to add the 'one more' symbol + to the end of the first token [a-z0-9\-]+

Note for future Stephen: When making changes to tokens in runway.php, I found I needed to go back to the Location tab on my post page and press save before the updated token would work.