Thread tagged as: Problem, Addons

How to do page conditionals in a header (global layout)

I've looked through the conditionals docs but my code doesn't seem to be working. I am trying to add a conditional statement to my global header so that I can display something if it is the homepage else, do something different.

Below is what I tried but I don't think it is correct as it is a global value, not inside a smaller template. I can't find the correct answer in the docs or the new forum.

<perch:if id="pageID" match="eq" value="1">
Andrew Cetnarskyj

Andrew Cetnarskyj 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Where's pageID coming from? Is it a layout attribute?

No I wasn't passing it in as a layout variable, I thought it would be globally available from the queries that are run for the page content?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not globally available.

Why not use a layout variable to indicate the home page?

Andrew, I hope this helps. Along the lines of what Drew is suggesting.



perch_layout('global.header', array(
    'homepage' => true



<?php if(perch_layout_var('homepage',true)) { // if it's the homepage output this?>

  <h1>Yep, it's the Homepage</h1>

<?php }else{ // otherwise output this?>

  <h1>Sorry, This isn't the Homepage!</h1>

<?php } ?>