Need to pull a custom handle image attribute into a custom pagelist block template.

Permalink 1 user found helpful
Hello C5 Community :)

I was hoping someone could steer me in the right direction here. I've created a custom 'pagelist' block template. Within that I'm trying to retrieve a thumbnail image from a custom attribute with the handle 'recent_news_thumb'.

My page list works great, the pages do have the attribute applied and an image uploaded. That part should be all set. Everything else is great.

At the top of my pagelist block I've tried to add the image helper.

defined('C5_EXECUTE') or die("Access Denied.");
$textHelper = Loader::helper("text"); 
$file = $page->getAttribute("recent_news_thumb");
if (is_object($file)) {
    $im = Loader::helper('image');

And then later I try to retrieve and display it with the following:

<a href="<?php  echo $link; ?>"><img src="<?php echo($page->getAttribute('recent_news_thumb')->getVersion()->getRelativePath());?>" width="84px" height="87px"></a>

If anyone can point me in the right direction I would greatly appreciate it. Thanks.

View Replies: View Best Answer
arrestingdevelopment replied on at Permalink Reply
I usually end up on here posting these exact kind of questions, so take my advice with a (BIG) grain of salt... although I'm taking most of this from Jordan Lev's great re-vamp of the page_list block view.php file - you can get it here: - so THAT at least bodes well. LOL!

I'd rework your header like this:
defined( 'C5_EXECUTE' ) or die("Access Denied.");
$textHelper = Loader::helper("text");
$ih = Loader::helper('image');

Then, inside the loop/foreach part that is processing array of pages the page_list has retrieved, add this:
$img = $page->getAttribute('recent_news_thumb');
$thumb = $ih->getThumbnail($img, 64, 9999);

Replace "64" with max width, "9999" with max height. The "9999" effectively means "no maximum size" for that particular dimension. If you're on Concrete5.4.2 or higher, you can also pass a 4th argument of TRUE to enable cropping.

Then, where you want to output your image, use this:
<img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />

If this works, it was all Jordan Lev's doing (as I mentioned, all of this was copied directly from his code). If it DOESN'T work, I'm sure it's my fault. LOL!

Hope this helps!

- John
sketch2k replied on at Permalink Reply
Thank you John!

This is definitely a step in the right direction.

Plugged in as is - it's not pulling my image, but the php is no longer dieing and makes its way through the for loop.

I'll review Lev's work and double check everything. Still appreciate your response!!

Best regards,
arrestingdevelopment replied on at Permalink Best Answer Reply

Sorry that wasn't a "silver bullet" that just did the trick! If you haven't done too much modification to the page_list template, you may want to consider downloading Jordan's re-vamped version from the Github link I posted before. I had trouble using the core block's template when I first tried, but find Jordan's code to be MUCH easier to understand and edit (plus he includes a bunch of example code for how to accomplish various tasks like grabbing attributes, images, etc). Since what I gave you came from his template, it might be easier to cut-and-paste from your current template into his to give that a try.

Let me know how you make out... or if you hit specific stumbling blocks. *I* may not be able to help, but surely *someone* on here can! ;D

- John
sketch2k replied on at Permalink Reply
Yeah, now that I've looked more closely, that's a thing of beauty. Works like a charm.

Thank you so much John! +Karma to you (and Jordan Lev!) ;)


The result will soon be up on the homepage (recent news) of:

JIC someone's interested in viewing an (admittedly) bulky but still resolution adaptive summertime theme for inspiration... Or go on a summer vacation and hang out with wake-boarders and good looking women. *shrugs*