Forum
Slug with - not working
If you look at this url: https://vlm.so53dev.co.uk/audi-car-leasing/ and click on the A1 the Audi A1 page loads ok. The slug is a1
However, if you go back to the https://vlm.so53dev.co.uk/audi-car-leasing/ page and this time click on the A3 Sportback, the Audi A3 Sportback page doesn't load ok. The slug is a3-sportback
You can do as above again and select the Audi A4 (slug a4) and the page loads ok. So it seems to be that for whatever reason the - in the slug is causing a problem.
What am I doing wrong?
This is my model.php page:
perch_layout('global/header');
if (perch_get('model_slug')) {
perch_collection('Model', [
'filter' => 'slug',
'template' => 'model_header.html',
'value' => perch_get('model_slug'),
]);
}
perch_layout('global/footer');
Can we see your Diagnostic Report please, it's a good idea to post this with each post to the forum.
Also what is set up for your Routes for this?
Hi Rachel,
Diagnostics
Routes:
See this screenshot https://www.evernote.com/l/Ai-Y9TeL42JMobTAls2Qw_Jhe6IRbLdN6Qg
The
slug
token will capture the dashes for you. If your slugs don't include dashes, you'll need to specify a custom token.and then use
https://docs.grabaperch.com/runway/routing/custom-tokens/
Thanks Drew,
However, I am slightly confused (not difficult!), the slug does include dashes in my template. I have this
The model field contents a mix of values depending on the model entered e.g. A1, A3 Sportback, 1 Series, X5 . In the database I can see the slug is saved as a1, a3-sportback, 1-series, x5 . Screenshot of the collection item in Perch: https://www.evernote.com/l/Ai9zAe_XBrpHCJLVP-7m_Co-PnZWzqMQ_fM
Where the slug doesn't have a dash in it, the front end page loads fine. It's when the slug does have a dash in it that I run into problems. See screenshot of collection item in Perch: https://www.evernote.com/l/Ai_qfLHjgyhGWIvvWyVhz7NSiLYE3PXm-R4 - this doesn't load the collection item on the front end.
I don't understand why I would need to enter a custom token the slug generated seems ok.
I tried the custom token but that didn't work either.
What happened? What was the debug output?
Ah, I should have turned debug on!
This has given a little more insight
Good: For this https://vlm.dev:8888/audi-a1-leasing
Bad: For this https://vlm.dev:8888/audi-a3-sportback-leasing
I don't understand in the bad one why the make slug is audi-a3 when it should be a3 and likewise the model_slug should be a3-sportback
I should be expecting to see
So you're still using the standard
slug
token? That's going to match the dashes that you do not want to match.Use the
carslug
(or whatever) custom token when no dash is allowed.Ok,
Using the custom token the following seem to now look correct
However the content isn't loading for either now
Debug says
model_header.html is
Scratch that. I've sorted... I think.
Thanks for your patience.
What I needed to do was create the route using the custom token for the make_slug but leave the model_slug as it was
I've still got a slight problem.
Where the make slug has a dash e.g. alfa-romeo I get same issue as I did with the model slug. However regardless as to how I configure the route I can't find a solution. In the end I just put a route in as 'alfa-romeo-[slug:model_slug]-leasing' which has the desired effect but not ideal as it's not dynamic and would need the client to create additional routes for other double barrelled makes (Mercedes-Benz etc.) as and when they add them.
I will keep trying things out but any other suggestions would be gratefully received
I don't think this is a Runway issue as such. You need to decide on the URL format you need that will still enable you to correctly identify the parts of the path that you need to extract. It sounds like what you're currently thinking of isn't predictable enough to reliably match across all circumstances.
Ok, that's fine Drew and I agree. So long as I know, saves me going round the houses!
There aren't too many double barrelled makes anyhow so I can manually insert specific routes during the site setup.
Thanks again.