Forum

Thread tagged as: Question

(solved) Is it possible to check a page attribute of a specific page?

I would like a single toggle somewhere (anywhere) in the admin that:

  1. Hides a specific page from the navigation, and
  2. Displays a banner on all pages when that specific page is NOT hidden from the navigation

My client wants to have a Jobs Posting page that they can toggle on/off as needed. So far I have a page attribute on a specific page to toggle navigation visibility:

<perch:pages id="jobs_page_toggle" type="checkbox" label="Hide Job Posting page?" value="hidden" suppress="true" />

When checked, the page link is not output into the main navigation:

<perch:if id="jobs_page_toggle" match="neq" value="hidden">
<!-- Output the navigation link only if not checked -->
</perch:if>

This works as expected.

But in addition to not showing the navigation item when the toggle is checked, I also want to display a small promo banner when it is unchecked (which again disappears when checked). I was hoping that the same page attribute could somehow control this as well.

I think this would mean checking a page attribute on a specific page and have if/else logic to test.

Something like:

<?php perch_page_attributes(array(
  'page'=>'/job-postings.php',
  'template' => 'job_posting.html'
)); ?>

And then in the job_posting.html attribute template:

<perch:if id="jobs_page_toggle" match="neq" value="hidden">
<p>A job posting is available.</p>
</perch:if>

(I realize the "page" option doesn't exist for perch_page_attributes, just showing an example.) This code works as intended, but only when on the job-postings.php page (which means it doesn't work for my purposes).

Again I am open to accomplishing this goal through any toggle in the admin area, so long as it is a single toggle to achieve 1 and 2 above. Any suggestions?

Richard Terrick

Richard Terrick 3 points

  • 3 years ago

Figured it out – perch_pages_navigation with include-parent => true was the key:

Sidebar code:

<?php perch_pages_navigation( array(
'from-path' => '/job-postings.php',
'template' => 'job_posting.html',
'include-parent' => true,
)); ?>

And the job_posting.html nav template:

<perch:if id="jobs_page_toggle" match="neq" value="hidden">
<p>A job posting is available.</p>
</perch:if>

Which checks for this page attribute:

<perch:pages id="jobs_page_toggle" divider-before="Job posting page" type="checkbox" label="Hide Job Posting page?" value="hidden" suppress="true" />