Forum

Thread tagged as: Question, Problem

Attempting to use page attribute to turn on/off page title

I've added a checkbox attribute to the default attribute templates with the intention of checking if it has been checked then displaying the page title on the page. I can't seem to get it to work at the moment and wondered if I was missing something.

My pages/attributes/default.html looks like this:

<perch:pages type="checkbox" id="showPageTitle" value="showTitle" label="Show page title" suppress="true" />

<perch:template path="pages/attributes/seo.html" />

And I'd like to do something similar to this:

    <?php if (perch_page_attribute('showPageTitle')) : ?>
        <h1><?php perch_pages_title() ?></h1>
    <?php endif ?>

I realise that the above code should output the attribute, which I don't want. But I'm not sure of the best way of doing this either.

Is it something to do with suppress=true? Am I only able to access the chekbox's value from inside a perch template?

Thanks!

Oliver Lowe

Oliver Lowe 0 points

  • 5 years ago
    <?php if (perch_page_attribute('showPageTitle')) ; ?>
        <h1><?php perch_pages_title() ?></h1>
    <?php endif ?>

I noticed a colon instead of semi-colon in perch_page_attribute(), this may be the problem but I did not test.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

@Robert - Oliver is using the alternate if syntax, this is valid PHP https://php.net/manual/en/control-structures.alternative-syntax.php

@Oliver can you not use Perch Conditionals in your template? https://docs.grabaperch.com/docs/templates/conditionals/if/

If not then to get the value back you would need to return the value:

$foo = perch_page_attribute('showPageTitle',array(),true);

Then you can test $foo.

@rachel I feel like a goofball. I didn't even notice the file extension so I thought it was a php page. Also, I guess it might be time for me to study up on te alternative syntax. ;)