Need homepage attribute to control the footer sitewide

Permalink
I have a chat module in the footer of my site. I have a Checkbox Page Attribute on the homepage that adds a style of hidden, so I can turn off the chat. However, it only works on the homepage even though my code is in the footer.

<?php $c = Page::getCurrentPage();
$chat = $c->getAttribute('chat');
// checked - string(1) "1"
// unchecked - string(1) "0"
if ($chat == '1') {
    echo '<style>';
    echo 'button.chat{display:none !important}';
    echo '</style>';
} else {
    echo '';
}
?>


Any help out there?

 
hutman replied on at Permalink Reply
hutman
Are you trying to get it so that the attribute on the homepage adds that class sitewide?
GrizzlyAdams replied on at Permalink Reply
Yes, that is exactly what I am looking for.
hutman replied on at Permalink Reply
hutman
Instead of
$c = Page::getCurrentPage();

You want
$page = Page::getByID(1);
GrizzlyAdams replied on at Permalink Reply
Hmmm, in the footer I have
<?php $page = Page::getByID(1);
$chat = $c->getAttribute('chat');
if ($chat == '1') {
    echo '<style>';
    echo 'button.chat{display:none !important}';
    echo '</style>';
} else {
    echo '';
}
?>


but it only hides it on the homepage. Am I missing something?
hutman replied on at Permalink Best Answer Reply
hutman
$page = Page::getByID(1);
$chat = $page->getAttribute('chat');
GrizzlyAdams replied on at Permalink Reply
I got it, had to have..
<?php $page = Page::getByID(1);
$chat = $page->getAttribute('chat');
if ($chat == '1') {
    echo '<style>';
    echo 'button.chat{display:none !important}';
    echo '</style>';
} else {
    echo '';
}
?>
pvernaglia replied on at Permalink Reply
pvernaglia
Your code is looking for the chat attribute on each individual page, you would need to set that attribute on every page you want to display the block in the footer. Instead of getting the page with getCurrentPage use one of the other functions to get the page by name, handle, ID, path, ect.