How to access a custom attributes in a block
Permalink
I am building a site in concretet5. I have some custom attributes, and I need to show those custom attributes in page_list block. I have tried a much by searching, but did not get my result.
Any help is appreciable.
Any help is appreciable.
That works nice for me. Thank you jordanlev. Can I just use that method to get a image coming from a page attribute ? But when I did that, it's showing a error, "Fatal error: Call to a member function getRelativePath() on a non-object in /var/www/TantraProjects/inhouse/cafe_restaurant/blocks/page_list/view.php on line 26"
Please help me to resolve this....
Please help me to resolve this....
there are already some blocks in the marketplace that allow you to display images in a page list block.
I did one called 'Page List Title' and one of the templates is a list view with thumbnails. You can take a look at the code to see how we did it or just use the block. here's what we used:
I did one called 'Page List Title' and one of the templates is a list view with thumbnails. You can take a look at the code to see how we did it or just use the block. here's what we used:
Actually the image is coming from a page attribute. I don't think, this method will work. Because this code is to get the default thumbnail.
You have used a block to show a image. Can you tell me some more about this.
You have used a block to show a image. Can you tell me some more about this.
To avoid the error, just check if the image exists before using it:
<?php $image = $page->getAttribute('your_attribute_handle'); if ($image) { //...do your image stuff here (generate a thumbnail, call ->getRelativePath(), etc.) //...and output the <img> tag here too } ?>
Thank you jordanlev. It works fine for me. Thank you again.
(This assumes you're inside the "foreach" loop in that view.php file.)