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


Go to End


7 Posts   1401 Views

Avatar
philwhite

Community Member, 24 Posts

26 July 2010 at 11:10am

Very impressed with the vast majority of SilverStripe. Thanks everyone for all their work!

I have a demo site up and it's going down well, but I would like to design the home page to include a couple of teasers and perhaps any newsflashes. To do this, I'd like to lift the next forthcoming event from two different calendars (makes sense, regional and national) and (mis)use a third calendar not visible elsewhere on the site to store newsflashes with expiry dates.

Has anyone done anything similar or can anyone give me a pointer to the code I need to be looking at before I start rummaging around on my own?

TIA

Avatar
philwhite

Community Member, 24 Posts

29 July 2010 at 10:54am

You must be sick of answering that question. Sorry.

I have three teasers to three calendars working fine. Just one question, though.

How can I query if UpcomingEvents returns empty, so that I can suppress the entire teaser?

Sorry, PHP novice.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

29 July 2010 at 3:11pm

<% if UpcomingEvents %> oughta do it, no?

Avatar
philwhite

Community Member, 24 Posts

29 July 2010 at 7:51pm

Edited: 30/07/2010 11:18am

That's what I assumed, and it works if all the calendars are empty, but I have 3. As I say, I am a PHP novice (the last time I programmed, it was about 20 years ago in C, and before that in COBOL and FORTRAN; OOPLs are pretty foreign to me), and I simply can't see how to scope UpcomingEvents to the regional-events calendar only in the "if" statement.

<div id="Teaserbar" class="typography">
	<div class="TeaserbarBox">
		<h3>
			Regional Events
  		</h3>
	<% control UpcomingEvents(3,regional-events) %>
  		<ul id="Teaser2">
		  	<b>$EventTitle</b>
			<li><% control Event %>$Content.LimitWordCount(60)<% end_control %><br><a href="$Link"><% _t('MORE','more...') %></a></li>
  		</ul>
	<% end_control %>
		<div class="clear"></div>
	</div>
	<div class="sidebarBottom"></div>
	<br>
...
</div>

works fine, but of course returns the header and an empty teaser box.

<div id="Teaserbar" class="typography">
<% if UpcomingEvents %>
	<div class="TeaserbarBox">
		<h3>
			Regional Events
  		</h3>
	<% control UpcomingEvents(3,regional-events) %>
  		<ul id="Teaser2">
		  	<b>$EventTitle</b>
			<li><% control Event %>$Content.LimitWordCount(60)<% end_control %><br><a href="$Link"><% _t('MORE','more...') %></a></li>
  		</ul>
	<% end_control %>
		<div class="clear"></div>
	</div>
	<div class="sidebarBottom"></div>
	<br>
<% end_if %>
...
</div>

works but only clears the box if all the calendars are a random calendar is empty.

<div id="Teaserbar" class="typography">
<% if UpcomingEvents(3,regional-events) %>
	<div class="TeaserbarBox">
		<h3>
			Regional Events
  		</h3>
	<% control UpcomingEvents(3,regional-events) %>
  		<ul id="Teaser2">
		  	<b>$EventTitle</b>
			<li><% control Event %>$Content.LimitWordCount(60)<% end_control %><br><a href="$Link"><% _t('MORE','more...') %></a></li>
  		</ul>
	<% end_control %>
		<div class="clear"></div>
	</div>
	<div class="sidebarBottom"></div>
	<br>
<% end_if %>
...
</div>

Returns a parse error on the last line of HomePage.ss (unexpected "{").

Avatar
philwhite

Community Member, 24 Posts

30 July 2010 at 11:24am

Been struggling with this all day now. I really can't see why the arguments for the UpcomingEvents function work fine in the control statement, but deliver an error in the if statement. Just makes no sense to me. I suppose I could define three functions in HomePage.php, each of which explicitly checks one calendar that I need, but that seems awfully tiresome.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

30 July 2010 at 12:24pm

Yeah, your <% if %> block is a bit too complex. SSViewer has some limitations.

You should probably just write a custom function..

public function UpcomingRegionalEvents() {
return $this->UpcomingEvents(3, "regional-events");
}

That way you just need <% if UpcomingRegionalEvents %> and don't need multiple arguments.

Avatar
philwhite

Community Member, 24 Posts

30 July 2010 at 9:23pm

That, of course, works like a dream. I thought I was being even more stupid than usual.
Thank you so much.

Now I'm on terra firma and only have the rest of the styling left to do.