How to output Calendar/Event image attribute
Permalink 1 user found helpful
I managed to work out how to add attributes to a Calendar Event as I want a thumbnail image (event_image) to display with each event listed on the Event List block. However I cannot seem to get the image attribute to display.
Many thanks in advance.
Many thanks in advance.
That's helpful, thanks for sharing. Where did you put the code? I tried putting it in concrete/blocks/calendar_event/view.php but it didn't seem to work.
Hi,
You shouldn't really change the files in the core folder 'concrete'. You should create a template file that you copy from concrete/blocks/block_name/view.php
To create a template file you copy the view.php file which you then place in application > blocks > calendar_event > templates > (rename the view.php file to) your_template_name.php
Note: The folder 'blocks' in 'application' is usually empty so you create the folder and name them exactly as they are in the concrete folder.
Example:
application > blocks > calendar_event > templates > your_template_name.php
ADDING IMAGE TO PAGE GENERATED BY CALENDARS & EVENTS
I created an image/file attribute under Calendars & Events in the dashboard.
Within the newly created template file I pasted, as you mentioned correctly, the code where I wanted the image to appear.
Make sure that the Calendar Event block then uses the template you have created by selecting the block and under Design & Custom Template > Custom Template > Your Template Name
The image then appears on the event page generated by Calendars & Events
DISPLAYING IMAGE IN EVENT LISTING
To get a thumbnail to appear in the Event List block I used the code below.
I wanted the thumbnail automatically cropped at a particular size so created an additional thumbnail (in system & settings > thumbnails) which I called 'event_thumbnail' but you can call in whatever thumbnail you want (small/medium/another name etc..).
Again I copied the view.php file but this time from 'event_list' and created a template:
application > blocks > event_list > templates > your_template_name.php
Does that help a bit?
You shouldn't really change the files in the core folder 'concrete'. You should create a template file that you copy from concrete/blocks/block_name/view.php
To create a template file you copy the view.php file which you then place in application > blocks > calendar_event > templates > (rename the view.php file to) your_template_name.php
Note: The folder 'blocks' in 'application' is usually empty so you create the folder and name them exactly as they are in the concrete folder.
Example:
application > blocks > calendar_event > templates > your_template_name.php
ADDING IMAGE TO PAGE GENERATED BY CALENDARS & EVENTS
I created an image/file attribute under Calendars & Events in the dashboard.
Within the newly created template file I pasted, as you mentioned correctly, the code where I wanted the image to appear.
<?php $img = $event->getAttribute('your_attribute_name'); if ($img) { $src = $img->getThumbnailURL('small'); echo \HtmlObject\Image::create($src); } ?>
Make sure that the Calendar Event block then uses the template you have created by selecting the block and under Design & Custom Template > Custom Template > Your Template Name
The image then appears on the event page generated by Calendars & Events
DISPLAYING IMAGE IN EVENT LISTING
To get a thumbnail to appear in the Event List block I used the code below.
I wanted the thumbnail automatically cropped at a particular size so created an additional thumbnail (in system & settings > thumbnails) which I called 'event_thumbnail' but you can call in whatever thumbnail you want (small/medium/another name etc..).
Again I copied the view.php file but this time from 'event_list' and created a template:
application > blocks > event_list > templates > your_template_name.php
<?php $img = $event->getAttribute('your_attribute_name'); if ($img) { $src = $img->getThumbnailURL('event_thumbnail'); echo \HtmlObject\Image::create($src); } ?>
Does that help a bit?
Awesome, that's a helpful walkthrough. Really appreciate it! I've been looking forward to using the new calendar block.
Hi Studio108,
I've been trying to implement this for an hour now and I am getting the error below on the call to the custom attribute.
Whoops \ Exception \ ErrorException (E_ERROR)
Call to a member function getAttribute() on null
Suggesting that the called attribute is empty I assume.
I have created the custom attribute in the dashboard under calendar/attributes, (EventImage) and I have populated it (I am still testing, clearly, so I only have one entry at this point.).
For reference I also created the event_thumbnail in System & Settings / thumbnail.
I'm including the code below. Has something changed since you posted this in relation to calling custom attributes?
Any thoughts on this would be hugely appreciated. I'm not the best with PHP, but this seemed straight forward, and I just can't get it to work.
I've carefully made sure that everything is spelled properly and so forth... I'm baffled at this point.
I've been trying to implement this for an hour now and I am getting the error below on the call to the custom attribute.
Whoops \ Exception \ ErrorException (E_ERROR)
Call to a member function getAttribute() on null
Suggesting that the called attribute is empty I assume.
I have created the custom attribute in the dashboard under calendar/attributes, (EventImage) and I have populated it (I am still testing, clearly, so I only have one entry at this point.).
For reference I also created the event_thumbnail in System & Settings / thumbnail.
I'm including the code below. Has something changed since you posted this in relation to calling custom attributes?
<div class="event_thumbnail"> <?php $img = $event->getAttribute('EventImage'); if ($img) { $src = $img->getThumbnailURL('event_thumbnail'); echo \HtmlObject\Image::create($src); } ?> </div>
Any thoughts on this would be hugely appreciated. I'm not the best with PHP, but this seemed straight forward, and I just can't get it to work.
I've carefully made sure that everything is spelled properly and so forth... I'm baffled at this point.
Hi, it has been a couple of years so I had to refresh my memory. It reminded me of how complicated the procedure is!
Had you done the actions listed below to assign the image attribute to a particular event calendar?
Have you created an Attribute 'Set' for the Event Calendar?
System & Settings > Attributes > Sets > Attribute Categories > Event (attached image 1)
I created one called 'Event Attributes'
If you then go to 'Attributes' under Calendar & Events, I created and assigned the 'Event Image' attribute to the 'Event Attributes' set. (attached image 2)
Then when you go to add an event to your calendar you will see the tab 'Event Attributes' under where you can link an image to the event. (see attached image)
As long as your image attribute name is the same in the coded Event List or Event Display view.php template (example below) it should appear.
I have tried this in version 8.5.1 and it works OK
I hope this has helped a bit??
Had you done the actions listed below to assign the image attribute to a particular event calendar?
Have you created an Attribute 'Set' for the Event Calendar?
System & Settings > Attributes > Sets > Attribute Categories > Event (attached image 1)
I created one called 'Event Attributes'
If you then go to 'Attributes' under Calendar & Events, I created and assigned the 'Event Image' attribute to the 'Event Attributes' set. (attached image 2)
Then when you go to add an event to your calendar you will see the tab 'Event Attributes' under where you can link an image to the event. (see attached image)
As long as your image attribute name is the same in the coded Event List or Event Display view.php template (example below) it should appear.
<?php $img = $event->getAttribute('EventImage'); if ($img) { $src = $img->getThumbnailURL('event_thumbnail'); echo \HtmlObject\Image::create($src); } ?>
I have tried this in version 8.5.1 and it works OK
I hope this has helped a bit??
I have selected the 'small' thumbnail that has been generated in the file manager but you can use whatever thumbnail you want.
You can find out more about image output options here
https://documentation.concrete5.org/tutorials/objective-ways-to-prin...