Forum

Thread tagged as: Question, Problem, Runway

Checking which page you are on in Runway

I'm converting a site from perch 2 to perch runway and I've got a little stuck on one small part.

I had a conditional in my header (which was loaded as an include) which checked the current page and stored its name as a variable so that later on i could conditionally load some css and javascript on just the homepage. It worked like this:

<?php $pageName = basename($_SERVER['PHP_SELF']); ?>

<?php if( $pageName == 'index.php' ){print '<link href="css/myconditionalcss.css" rel="stylesheet" type="text/css"/>';} ?>

Well... that no longer works in perch runway and i'm not really sure what to replace it with. Any ideas?

Daniel Owen

Daniel Owen 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does PerchSystem::get_page() help?

Hi Drew, I'm not sure! Mainly because i don't know what i would check for in <?php if( $pageName == 'index.php' ) The page title is "Home page", i tried that and got nothing but i'm guessing that's not what i need.

D'oh! Don't mind me! I echoed the variable to see what it was returning for the page (and of course it was / for the homepage!) And yep, it works now! Thank you Drew :^)

Just for anyone else trying to do this, the revised version of the code i originally posted is:

<?php $pageName = PerchSystem::get_page(); ?>

<?php if( $pageName == '/' ){print '<link href="css/myconditionalcss.css" rel="stylesheet" type="text/css"/>';} ?>