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


Reply

7 Posts   755 Views

Avatar
philwhite

26 July 2010 at 11:10am Community Member, 24 Posts

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

29 July 2010 at 10:54am Community Member, 24 Posts

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

29 July 2010 at 3:11pm 4085 Posts

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

Avatar
philwhite

29 July 2010 at 7:51pm (Last edited: 30 July 2010 11:18am), Community Member, 24 Posts

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

30 July 2010 at 11:24am Community Member, 24 Posts

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

30 July 2010 at 12:24pm 4085 Posts

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

30 July 2010 at 9:23pm Community Member, 24 Posts

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.