Page Defaults error

Permalink
Hi,

I understand that page defaults are where you can pre-populate a page with blocks. But every time I try to edit page defaults i get this error:

) Fatal error: Call to a member function getRelativePath() on a non-object in C:\wamp\www\asap\themes\asap\news_post.php on line 81 Call Stack #TimeMemoryFunctionLocation 10.0007671712{main}( )..\index.php:0 20.0023763440require( 'C:\wamp\www\asap\concrete\dispatcher.php' )..\index.php:2 30.622616830656Concrete5_Library_View->render( )..\dispatcher.php:258 40.782721178208include( 'C:\wamp\www\asap\themes\asap\news_post.php' )..\view.php:929

Please see screengrab attached

1 Attachment

 
mhawke replied on at Permalink Reply
mhawke
What's on line #81 of '[root]\themes\asap\news_post.php ?
ahhaweb99 replied on at Permalink Reply
<div class="grid has-image" style="background-image:url(<?php echo $c->getAttribute('blogListImage')->getRelativePath(); ?>)">
mhawke replied on at Permalink Reply
mhawke
Try this instead:

<?php echo ($c->getAttribute('blogListImage')->getVersion()->getRelativePath());?>


It has a 'getVersion()' in the middle.

Courtesy ofhttp://www.weblicating.com/c5/cheat-sheet/...
ahhaweb99 replied on at Permalink Reply
Hi Thanks for this. It didnt work though :(

I'm kinda thinking its because the getAttribute('blogListImage') has no value at that point. Is there anything i can add like an if statement to say if this value doesnt exist then use something else. So this attribute doesnt return null. I could be barking up the wrong tree though.
mhawke replied on at Permalink Best Answer Reply
mhawke
This works on my quick setup:
<div class="grid has-image" style="background-image:url(<?php if ($c->getAttribute('blogListimage')) { echo $c->getAttribute('blogListimage')->getVersion()->getRelativePath();} ?>);height:200px">


I can save a Page Type Default without crashing.
ahhaweb99 replied on at Permalink Reply
Thats it! The if statement i was looking for. I'm pretty new to PHP and Concrete5 so i guess the if statement there is common syntax. In fact its helped me solve something else too. You saved my ass more than once. :) Thanks for your help!
mhawke replied on at Permalink Reply
mhawke
Glad I could help.

That 'cheat sheet' I linked to above is a really helpful thing.
jordanlev replied on at Permalink Reply
jordanlev
Glad that @mhawke's solution worked for you. Just an FYI, you don't need the ->getVersion() call in there. It won't break anything, but it's entirely superfluous and the code will look a little nicer without it (IMO).