Forum

Thread tagged as: Question

How do I check for a page attribute value?

I have a check box in the page attribute template. How can I do something on a page if that checkbox is checked (ie value = true)?

This doesn't work:

if (perch_page_attribute('deactivate', true)=='true') {
PerchSystem::redirect('/redirected-page.php');
}
Lisa Morena

Lisa Morena 1 points

  • 6 years ago

Lisa Morena said:

I have a check box in the page attribute template. How can I do something on a page if that checkbox is checked (ie value = true)?

This doesn't work:

if (perch_page_attribute('deactivate', true)=='true') {
PerchSystem::redirect('/redirected-page.php');
}

Have you tried just this...

if (perch_page_attribute('deactivate', true)) {
PerchSystem::redirect('/redirected-page.php');
}

No joy with that either :(

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us your attribute template?

<perch:pages id="deactivate" type="checkbox" label="Deactivate this page" help="Tick this box to deactivate this page" value="true" suppress="true"  />
Drew McLellan

Drew McLellan 2638 points
Perch Support

That looks like it should work!

It doesn't :(

Does the page it redirects to have to have been created in Perch for PerchSystem::redirect to work? It does have perch regions on it but was not created by perch itself.

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, it just issues an HTTP Location: header.

Hmph... no idea why it's not working then!