Forum
How to add a page name into an if statement?
Hi
I've put together a careers list and detail page using the code below. I'm using Perch Runway and collections.
The elseif
and the else
parts work fine. It's the if statement
that I can't figure out.
I think what it needs to say is: If the page URL contains careers
followed by a slug
show this.
How do I add the page careers
into if (perch_get('s'))
// How would I modify this first if statement to only show if the URL contains /careers/job-name-here/
// URL: /careers/job-name-here/apply-for-this-job
if (perch_get('s')) {
perch_collection('Careers', array(
'template' =>'job-form.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));
}
elseif (perch_get('s')) {
// Displays single job in careers collection filtered on slug
// URL: /careers/job-name-here/
perch_collection('Careers', array(
'template' =>'job-detail.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));
}
else {
// Lists all jobs in careers collection
// URL: /careers/
perch_collection('Careers', array(
'template' =>'job-list.html',
));
}
What does your route look like?
Hi Drew
At the moment I've only setup a route for the slug for the detail page:
... thinking about it my initial idea probably won't work...
I need a way to get a third page (containing an application form) into the list and detail setup. So it'd be list jobs page, show job detail page, show application page.
So how about adding another route something like:
Then you can use
Brilliant. Thanks for your help Drew.