C5.7 Getting page attribute in template

Hi! I have added a page attribute "slideshow" to C5. This attribute is now included (checked) in all my pages where a slideshow should show up at the top of the page. I´m calling this slideshow from javascript so I need to identify on which page the attribute "slideshow" is checked or not.

I´m thinking about giving the body a class with "slideshowTrue" or "slideshowFalse" and call the slideshow with js depending on this class.

But how is it possible (5.7) to get the value of this page attribute to append its value to the body?


View Replies: View Best Answer
MrKDilkington replied on at Permalink Reply
Hi micrdy,

Here is something you can try.
<body <?php if ($c->getAttribute('slideshow')) { echo 'class="slideshowTrue"'; } else { echo 'class="slideshowFalse"'; } ?>>
micrdy replied on at Permalink Best Answer Reply
That´s the code I´m using now. Thanks!

$page = \Page::getCurrentPage();
$value = $page->getAttribute('slideshow');

Where $value is now 0 or 1
MrKDilkington replied on at Permalink Reply
You can just use $c.

"Retrieving the Current Page Object

From within a Page Template

Within a page template (e.g. a template file found in a theme or a single page template) you don't have to do anything to retrieve the current page object. It's already present in the local scope:

(The $c stands for "current page.")"