Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » Adding an Image to the Event Calendar

Discuss all other Modules here.

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

Page: 1 2 3
Go to End
Author Topic: 3916 Views
  • OutrunTheWolf
    Avatar
    Community Member
    34 Posts

    Adding an Image to the Event Calendar Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding an Image to the Event Calendar Link to this post

    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.

  • OutrunTheWolf
    Avatar
    Community Member
    34 Posts

    Re: Adding an Image to the Event Calendar Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding an Image to the Event Calendar Link to this post

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

  • OutrunTheWolf
    Avatar
    Community Member
    34 Posts

    Re: Adding an Image to the Event Calendar Link to this post

    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

    Attached Files
  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding an Image to the Event Calendar Link to this post

    Can you post your PHP file?

  • OutrunTheWolf
    Avatar
    Community Member
    34 Posts

    Re: Adding an Image to the Event Calendar Link to this post

    Yeah, here we go

    Attached Files
  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding an Image to the Event Calendar Link to this post

    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.

    3916 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.