Is it possible to get custom page attributes from helper file?
Permalink 1 user found helpful
I have some page templates (in a 5.6 install) that use the below snippet to change a header background image using inline css with a custom page image attribute if it is set.
I was looking to move this snippet to a function in a helper file and then call it into my templates where required using something like
Purely with a view to neatening things up :-)
However I can't get this to work, I get an error
"Fatal error: Call to a member function getCollectionAttributeValue() on null in..[helper file]"
Is what I'm trying to do not possible, can I not get a page attribute outside the page because it's not yet fully initialised or something similar?
I know I've got the helper file set up right as if I can change the code to just echo out a test message into the page and this works fine.
if ($file = $c->getAttribute('header_image')) { $url = "'".$file->getVersion()->getDownloadURL()."'"; echo 'style="background-image: url('.$url.');"'; }
I was looking to move this snippet to a function in a helper file and then call it into my templates where required using something like
echo Loader::helper('myhelper')->headerImage();
Purely with a view to neatening things up :-)
However I can't get this to work, I get an error
"Fatal error: Call to a member function getCollectionAttributeValue() on null in..[helper file]"
Is what I'm trying to do not possible, can I not get a page attribute outside the page because it's not yet fully initialised or something similar?
I know I've got the helper file set up right as if I can change the code to just echo out a test message into the page and this works fine.
then where you declare the function in your helper: