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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Event Calendar Widget on Home page


Go to End


34 Posts   10046 Views

Avatar
Anaya

Community Member, 42 Posts

29 May 2009 at 1:10am

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

Forum Moderator, 4102 Posts

29 May 2009 at 1:40am

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

Avatar
Anaya

Community Member, 42 Posts

29 May 2009 at 2:22am

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

Forum Moderator, 4102 Posts

29 May 2009 at 2:35am

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

Community Member, 42 Posts

29 May 2009 at 3:30am

Edited: 29/05/2009 3:31am

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

Community Member, 42 Posts

2 June 2009 at 12:13am

Edited: 02/06/2009 12:15am

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

Forum Moderator, 4102 Posts

2 June 2009 at 1:34am

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

Community Member, 42 Posts

2 June 2009 at 10:08pm

Thanks UncleCheese,

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

regards
anaya.

Go to Top