DV-JF Posted February 14, 2014 Share Posted February 14, 2014 Hi, for a website witch is supposed to listen some events I'm trying to add the date-field from my "event-template" to the page URL so that the URL is something like this: example.com/events/2014-02-14_title-of-event/ All single-events are children of the page "events" I've tried $pages->addHookAfter('Page::path', null, 'hookPagePath'); function hookPagePath(HookEvent $e) { $page = $e->object; if($page->template == 'article') $e->return = "/$page->startdate_$page->name/"; } and the URL is rewritten correctly, but every time I try to reach this URL I get an 404 error. I've read this topic, but I think URL segments won't work for me, cause I try to work with an underscore. Can you help? Link to comment Share on other sites More sharing options...
Philipp Posted February 14, 2014 Share Posted February 14, 2014 I'm not sure if your code snippet is right. Is the template name really "article"? Wouldn't it be easier to hook after a page with the template is saved and then change the name of the page according to the date field? 1) Hook after page is saved 2) Change name of the page to startdate_oldname 3) save the page. Link to comment Share on other sites More sharing options...
Soma Posted February 14, 2014 Share Posted February 14, 2014 Ok again for the record. This hook just changes the page url and not the request of loading the page with that url. You need url segments to do that and there's no problem with underscores. Philipps solution is also good one. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now