How to access a custom attributes in a block

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.

View Replies: View Best Answer
jordanlev replied on at Permalink Best Answer Reply
Look at the code comments in the Page List block's view.php file. You'll see an example of how to get a page's attribute:
$value = $page->getAttribute('your_attribute_handle');

(This assumes you're inside the "foreach" loop in that view.php file.)
girijadash09 replied on at Permalink Reply
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....
cannonf700 replied on at Permalink Reply
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:
      $pt = $cobj->getCollectionAttributeValue('thumbnail');
      echo("<a href=\"$link\">");
      $imgHelper->outputThumbnail($pt, 75,75, $title);
girijadash09 replied on at Permalink Reply
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.
jordanlev replied on at Permalink Reply
To avoid the error, just check if the image exists before using it:
$image = $page->getAttribute('your_attribute_handle');
if ($image) {
  // your image stuff here (generate a thumbnail, call ->getRelativePath(), etc.)
  //...and output the <img> tag here too
girijadash09 replied on at Permalink Reply
Thank you jordanlev. It works fine for me. Thank you again.