File attribute error ONLY on Edit Page Defaults
Permalink
Hey there, this is my first ever post here on the community. Usually I find all the answers just by searching here or simply reading the Documentation, so I never needed to ask anything.
I'm building a site where I use a custom attribute to display an image as full page background, and I want it hardcoded into the page template so I used this code:
The image displays with no problem on every page, EXCEPT when I want to edit Page Type Defaults.
There, I get an error saying "Call to a member function getRelativePath() on a non-object"
I need help, I can't figure out how to overcome this.
I'm building a site where I use a custom attribute to display an image as full page background, and I want it hardcoded into the page template so I used this code:
echo '<img src="'.$page->getAttribute('bgimage')->getRelativePath().'">';
The image displays with no problem on every page, EXCEPT when I want to edit Page Type Defaults.
There, I get an error saying "Call to a member function getRelativePath() on a non-object"
I need help, I can't figure out how to overcome this.
If that is the case, continue reading.
I had a similar issue when inheriting attributes and styles from a parent page, since page type defaults don't have parents. What you can do is specifically set $page to a value if the page type defaults are being loaded.
Alternatively, you could check to see if $page was set, and if not them skip the entire echo. But you may have other things that rely on $page.
Hope that helps!