Displaying 'calendar attributes' from events page...

Permalink
Hi there, I have successfully created a calendar with an image attribute 'thumbnail'

I can get my 'event list' to display my attribute by using:

$thumbnail = $event->getAttribute('thumbnail');

but how can I get this image to display on the actual event page? $event throws up an error: Call to a member function addClass() on null (and I don't want to needlessly add a page attribute and assign the thumbnail twice)

It must be in there somewhere, but I can't work out how to access it...

If anyone can point me in the right direction, I'd be most grateful.

Thanks

rc255
View Replies:
studio108 replied on at Permalink Reply
studio108
I answered a similar question a while back.

https://www.concrete5.org/community/forums/customizing_c5/how-to-out...

Hope this helps?
rc255 replied on at Permalink Reply
rc255
Thanks studio108, I now see where I was going wrong.

My code was correct, but I hadn't put it into the 'event list block'. Instead, I had hard-coded it directly into my events.php page type... Got it working now.

One more quick question. How do I apply a class to the thumbnail in the events list block?

$img = $event->getAttribute('your_attribute_name');
if ($img) {
$src = $img->getThumbnailURL('event_thumbnail');
echo \HtmlObject\Image::create($src);
}

That would be the icing on the cake!

Cheers
studio108 replied on at Permalink Reply
studio108
Hi,

if you look at the code each event is wrapped with this div class ''ccm-block-calendar-event-list-event''
so you could target the image that way with something like.
.ccm-block-calendar-event-list-event img { css styling here...}


Or another way could be to wrap just the image with a div?

<div class="event_thumbnail_wrapper">
<?php
            $img = $event->getAttribute('event_image');
            if ($img) {
            $src = $img->getThumbnailURL('event_thumbnail');
            echo \HtmlObject\Image::create($src);
            }
?>  
</div>


I am sure there is also a way of just adding a class to the img but my php isn't the best.
rc255 replied on at Permalink Reply
rc255
studio108,

I just worked it out... if you extend out the 'echo' line to:

echo \HtmlObject\Image::create($src)->class('my-image-class');

it does the trick :)
studio108 replied on at Permalink Reply
studio108
Thanks for that I've learnt something also!