Forum

Thread tagged as: Question, Runway

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',            
        ));  
        }
Stephen Meehan

Stephen Meehan 4 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does your route look like?

Hi Drew

At the moment I've only setup a route for the slug for the detail page:

 careers/[slug:s]

... 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.

Drew McLellan

Drew McLellan 2638 points
Perch Support

So how about adding another route something like:

 careers/[slug:s]/[apply:apply]

Then you can use

 if (perch_get('apply')) 

Brilliant. Thanks for your help Drew.