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

Event Calendar Widget on Home page


Go to End
Reply

34 Posts   6494 Views

Avatar
Anaya

29 May 2009 at 1:10am Community Member, 42 Posts

Hi Guys,

I have been trying to put actual calendar on home page.
As mentioned in one of the threads, have put following code in Homepage.php in controller block -
function GlobalCalendarWidget()
{
$calendarPage = DataObject::get_one("Calendar"); // If you have multiple calendars, specify an id or url segment.
return new CalendarWidget($calendarPage);
}

But really dont have any idea how to call it in template.
Can I do tht? And if yes, whats the syntax for calling it in template.
Have tried lot of options like $CalendarWidget...but that still does not work..

I know its very basic thing...but dont know how to do that.
Need your help!

Regards
Anaya...

Avatar
UncleCheese

29 May 2009 at 1:40am 4085 Posts

$GlobalCalendarWidget is what you want. If that's not working, post your template and homepage controller code.

Avatar
Anaya

29 May 2009 at 2:22am Community Member, 42 Posts

Hi UncleCheese,

Even I had tried $GlobalCalendarWidget, but after flushing the pag, blank page appears.
As asked, here is the homepage.php code -

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
'AnnouncementText' => 'HTMLText'
);
static $has_one = array(
);

   function getCMSFields()
   {
   $fields = parent::getCMSFields();
   $fields->addFieldToTab('Root.Content.Announcement', new HtmlEditorField('AnnouncementText', 'Announcement'));
   return $fields;
   }   
}

class HomePage_Controller extends Page_Controller {
function LatestNews($num=3) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}

function UpcomingEvents()
{
return DataObject::get_one("Calendar")->upcomingEvents(5);
}

function GlobalCalendarWidget()
{
$calendarPage = DataObject::get_one("Calendar"); // If you have multiple calendars, specify an id or url segment.
return new CalendarWidget($calendarPage);
}
   
}
?>

Code for homepage template which is in Layout folder -
<div id="contentLeft">
$Content
$Form
</div>
<div id="contentRight">
<h3>News</h3>
<div class="marquee_text"><marquee scrolldelay = "100"><p>$AnnouncementText</p></marquee>
</div>
<div class="NewsListHomeIn">
<% control LatestNews %>
<a href="$Link" title="$Title" class="newsTitle">$Title</a>
<div class="news_img">$Photo.SetWidth(75)</div>
<div class="news_text">
$Content.LimitWordCount(10)<br/>
<a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a>
</div>
<div class="clear"></div>
</div>
<% end_control %>
</div>
$GlobalCalendarWidget
</div>
<div class="clear"></div>

Regards

Avatar
UncleCheese

29 May 2009 at 2:35am 4085 Posts

Blank page usually means a PHP error. Can you crank up your error reporting or check your logs for what it might be throwing?

Avatar
Anaya

29 May 2009 at 3:30am (Last edited: 29 May 2009 3:31am), Community Member, 42 Posts

Hey,
I cant find out whts wrong in php code???
PHP error means in Homepage.php page...right???
Any idea abt wht could be wrong in the php code...

Regards

Avatar
Anaya

2 June 2009 at 12:13am (Last edited: 2 June 2009 12:15am), Community Member, 42 Posts

Hi Guys,

As mentioned in my other post, Event calendar is appearing in Firefox...
[link]http://silverstripe.org/all-other-modules/show/261483#post261483[/link]
But I am not able to get it working on home page...
Earlier upcoming events were appearing, but after using code from below link, it stopped working...
[link]http://bluehousegroup.svn.beanstalkapp.com/modules/trunk/event_calendar/ [/link]
The code in HomePage.php -
function GlobalCalendarWidget()
{
$calendarPage = DataObject::get_one("Calendar"); // If you have multiple calendars, specify an id or url segment.
return new CalendarWidget($calendarPage);
}
function UpcomingEvents()
{
return DataObject::get_one("Calendar")->upcomingEvents(5);
}

Pls pls let me know wht wrong i am doing???
I have been working on this for two days...need to sort out this urgently...

Regards
Bhagyashri

Avatar
UncleCheese

2 June 2009 at 1:34am 4085 Posts

The GlobalCalendarWidget() function needs to be in a controller. Put it in the Page_Controller to have the most flexibility. Then you can put it on any page you want.

Avatar
Anaya

2 June 2009 at 10:08pm Community Member, 42 Posts

Thanks UncleCheese,

for your suggestion...
its working fine now...

regards
anaya.

Go to Top