Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8026 Posts in 1851 Topics- by 2099 Members - Latest Member: roi
Calendar Script CommunityCustomizationCustomizing CalendarScript (Moderators: scott, DanO, Marty)Limiting the number of displayed events
Pages: [1]   Go Down
Print
Author Topic: Limiting the number of displayed events  (Read 359 times)
0 Members and 1 Guest are viewing this topic.
snooty1972
New Member
*

Karma: 0
Offline Offline

Posts: 0


« on: September 29, 2004, 03:10:00 PM »

Could someone take a look at my template and let me know where I'm going wrong. I'm also trying to limit the number of events show e.g. to the first 5 but so far the below is not working (this was based on a previous forum post)

Thanks

<%
&getEvents( {'duration'=>$in{duration}} );
$DAY = $Grid->{'grid'}->

  • ->
  • ;
    $EVENTS = $DAY->{events};
    $total_events=5;
    %>
    <%EVENTLOOP:%>
    <%FOREACH EVENTLIST%>
    <%IF EVENTS EXIST%>
    <BR>
    <%FOREACH EVENT%>
    <%$total_events++;%>
    <%if (total_events == 5) { last EVENTLOOP; } %>
    <img src="http://www.regenthall.co.uk/regent/images/plus.gif" width=15 height=9 border=0>
    <A class=title HREF="<%=$CGI_URL_QUERYSTRING%>calendar=&template=&view=Event&event_id=<%=$EVENT->{'details'}->{'id'}%>"><%= $EVENT->{'details'}->{'title'} %></A><BR>
    <% if ($EVENT->{'schedule'}->{'start_time'}) { %><%= $EVENT->{'schedule'}->{'start_time'} %><% } %>

    <% if ($EVENT->{'schedule'}->{'start_time'}) { %> : <% } %>
    <%=$DAY->{dayname}%>, <%=$DAY->{monthname}%> <%=$DAY->{dd}%><BR>
    <%/FOREACH%>
    <%/IF%>
    <%/FOREACH%>

    <%unless($total_events){%>
    <CENTER><I>No Events</I>
    <% } %>

Logged
delicia
New Member
*

Karma: 0
Offline Offline

Posts: 5


WWW
« Reply #1 on: September 29, 2004, 08:28:00 PM »

on the first line where you set total_events = 5; change the variable name to $max_events. then when you do the comparison, change 5 to $max_events.

i think your problem is that you're setting total_events to 5 and then you increment it from there. so after the first event, your variable is 6. when you do the comparison, it's never exactly equal to 5.

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 221

Please don't PM me. Post in the open forum.


WWW
« Reply #2 on: September 30, 2004, 12:24:00 AM »

<%if (total_events == 5) {

"total_events" is a string, it will never equal 5.

Dan O.

------------------

Logged
snooty1972
New Member
*

Karma: 0
Offline Offline

Posts: 0


« Reply #3 on: September 30, 2004, 04:55:00 PM »

If I understood you correctly the new code would look as follows however this returns an error in line 12. Sorry, as you can see I am not a Pearl programmer. I'm guessing I've gotten the syntax wrong?

<%
&getEvents( {'duration'=>$in{duration}} );
$DAY = $Grid->{'grid'}->

  • ->
  • ;
    $EVENTS = $DAY->{events};
    $max_events=5;
    %>
    <%EVENTLOOP:%>
    <%FOREACH EVENTLIST%>
       <%IF EVENTS EXIST%>
       <BR>
          <%FOREACH EVENT%>
             <%$total_events++;%>
             <%if (total_events == max_events) { last EVENTLOOP; } %>
             <img src="http://www.regenthall.co.uk/regent/images/plus.gif" width=15 height=9 border=0>
             <A class=title HREF="<%=$CGI_URL_QUERYSTRING%>calendar=&template=&view=Event&event_id=<%=$EVENT->{'details'}->{'id'}%>"><%= $EVENT->{'details'}->{'title'} %></A><BR>
             <% if ($EVENT->{'schedule'}->{'start_time'}) { %><%= $EVENT->{'schedule'}->{'start_time'} %><% } %>

             <% if ($EVENT->{'schedule'}->{'start_time'}) { %> : <% } %>
             <%=$DAY->{dayname}%>, <%=$DAY->{monthname}%> <%=$DAY->{dd}%><BR>
          <%/FOREACH%>
       <%/IF%>
    <%/FOREACH%>

    <%unless($total_events){%>
    <CENTER><I>No Events</I>
    <% } %>

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 221

Please don't PM me. Post in the open forum.


WWW
« Reply #4 on: September 30, 2004, 08:43:00 PM »

Try just adding a "$" to the string you used in your original conditional to make it a variable like it should be.

<%if ($total_events == 5) {

JFYI

Dan O.

------------------

Logged
snooty1972
New Member
*

Karma: 0
Offline Offline

Posts: 0


« Reply #5 on: October 01, 2004, 02:43:00 AM »

We're getting there. I did as you suggested and added to $ to signify it is a variable. I also changed the total events declaration from 5 to 0 so that the count starts at 0 rather than 5. The result is nearly there. It now only shows 4 events BUT is also has the error message "Label not found for "last EVENTLOOP" at (eval 1) line 12.". This obviously means that the eventloop is working but something else is wrong that wasn't being round previously.

Here's the new nealy working code:

<%
&getEvents( {'duration'=>$in{duration}} );
$DAY = $Grid->{'grid'}->

  • ->
  • ;
    $EVENTS = $DAY->{events};
    $total_events=0;
    %>
    <%EVENTLOOP:%>
    <%FOREACH EVENTLIST%>
    <%IF EVENTS EXIST%>
    <BR>
    <%FOREACH EVENT%>
    <%$total_events++;%>
    <%if ($total_events == 5) { last EVENTLOOP; } %>
    <img src="http://www.regenthall.co.uk/regent/images/plus.gif" width=15 height=9 border=0>
    <A class=title HREF="<%=$CGI_URL_QUERYSTRING%>calendar=&template=&view=Event&event_id=<%=$EVENT->{'details'}->{'id'}%>"><%= $EVENT->{'details'}->{'title'} %></A><BR>
    <% if ($EVENT->{'schedule'}->{'start_time'}) { %><%= $EVENT->{'schedule'}->{'start_time'} %><% } %>

    <% if ($EVENT->{'schedule'}->{'start_time'}) { %> : <% } %>
    <%=$DAY->{dayname}%>, <%=$DAY->{monthname}%> <%=$DAY->{dd}%><BR>
    <%/FOREACH%>
    <%/IF%>
    <%/FOREACH%>

    <%unless($total_events){%>
    <CENTER><I>No Events</I>
    <% } %>

Logged
delicia
New Member
*

Karma: 0
Offline Offline

Posts: 5


WWW
« Reply #6 on: October 01, 2004, 07:56:00 AM »

mine has the comparison after the event is printed and uses 'exit'. don't  a lot about perl; i got this from an old message here:

      <%FOREACH EVENT%>
         •
         <% $total_trueevents++;%>
         <% if ($EVENT->{'schedule'}->{'start_time'}) { %><%= $EVENT->{'schedule'}->{'start_time'} %><% } %>
         <% if ($EVENT->{'schedule'}->{'end_time'}) { %>-<%= $EVENT->{'schedule'}->{'end_time'} %><% } %>
         <% if ($EVENT->{'schedule'}->{'start_time'}) { %> : <% } %>
         <%= $EVENT->{'details'}->{'title'} %><BR>
         <% if($total_trueevents >= $max_events) {
            exit();
         }%>
      <%/FOREACH%>

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 221

Please don't PM me. Post in the open forum.


WWW
« Reply #7 on: October 01, 2004, 12:57:00 PM »

** Label not found for "last EVENTLOOP"

Remove the line

<%EVENTLOOP:%>

(I don't know that such structure is supported - or correct)

Change "last EVENTLOOP;" to just

last;

** It now only shows 4 events **

Change the conditional ($total_events == 5) to

($total_events > 5)

OR move that line further down in the routine like before the first <%/FOREACH%>

Dan O.

------------------

Logged
snooty1972
New Member
*

Karma: 0
Offline Offline

Posts: 0


« Reply #8 on: October 03, 2004, 02:18:00 PM »

Thanks Dan. That all works perfectly now. Really appreciated!
Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 221

Please don't PM me. Post in the open forum.


WWW
« Reply #9 on: October 03, 2004, 04:35:00 PM »

Glad to hear it.

Dan O.

------------------

Logged
Pages: [1]   Go Up
Print
Jump to: