Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Adding an Image to the Event Calendar


Go to End
Reply


23 Posts   4041 Views

Avatar
OutrunTheWolf

Community Member, 34 Posts

29 June 2009 at 3:49am

Hello all,

I'm trying to add an Image field to the Event Calendar. I followed Tutorial 2, and ended up with this in:

CalendarEvent.php

class CalendarEvent extends Page
{

static $has_one = array (
       'EventPhoto' => 'Image'

   );
}

public function getCMSFields()
   {
      
      $f = parent::getCMSFields();
      
   
       $f->addFieldToTab("Root.Content.Images", new ImageField('EventPhoto'));

   return $f;

That works fine as far as I can see. In the CMS, under Page Type Calendar Event there is an image tab, and it lets me upload the image.

Th problem comes with the site, when I try to get the image in the code:

<div id="Photo">
$EventPhoto
</div>

I just end up with a "Website Error" Screen, when I acces the particular event.

Does anyone have any ideas on where i'm going wrong?

Avatar
UncleCheese

4085 Posts

29 June 2009 at 4:42am

I recommend you read the tutorial on extending the EventCalendar in the SS Wiki. I go through several levels of customization in there, including adding an image. You should not be modifying the core event_calendar code because when updates come out you'll lose your changes. You need to extend the classes in your mysite folder to keep your changes isolated.

Avatar
OutrunTheWolf

Community Member, 34 Posts

29 June 2009 at 5:03am

Edited: 29/06/2009 5:40am

Thanks again Cheese.

EDIT

Ok Cheese, I ran through the extending the event calender tutorial, I understand what is happening. But when you reach the end:

Setting up the templates

The next thing we have to do is set up templates for both the WorkshopHolder and Workshop class that include our new fields.

We’ll start by copying the base calendar template from /event_calendar/templates/Layout/Calendar.ss

Now, somewhere below the content, we need to add some of the custom Workshop fields we created. Remember, the Events control returns CalendarDateTime objects, so we need to refer to the $Event accessor to get to those fields.

We’ll add the following below the $_Content line...........

So, I copy the content from the original calendar.ss and calenderholder.ss files, into Workshop.ss and WorkshopHolder.ss, added the additional code. But where do I save the Workshop.ss files?

Avatar
UncleCheese

4085 Posts

29 June 2009 at 8:40am

In your mysite or theme directory. /templates/Layout/MyCalendarClass.ss -- just like the module has it set up.

Avatar
OutrunTheWolf

Community Member, 34 Posts

29 June 2009 at 9:37am

Edited: 29/06/2009 9:38am

Well,

After a lot of work, I haven't managed to get any further. I can't seem to get image working for each individual event, it doesn't show up.

I have attached my ss file.

To make sure:

mysite/code/
Workshop.php
WorkshopHolder.php

mysite/templates/Layout/
Workshop.ss
WorkshopHolder.ss

If you get a chnace to take a look at my files pls do, it might reveal where i'm going wrong.

Thanks

Avatar
UncleCheese

4085 Posts

30 June 2009 at 1:37am

Can you post your PHP file?

Avatar
OutrunTheWolf

Community Member, 34 Posts

30 June 2009 at 2:27am

Yeah, here we go

Avatar
UncleCheese

4085 Posts

30 June 2009 at 2:56am

And just to be sure, in the CMS the page type is WorkshopHolder and the event is created as a Workshop? What happens when you put some static text on that template? Does it render? Just want to make sure it's reading the right template.

Go to Top