We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Problem, Events

Paginating a Perch Variable

Hi guys,

I'm trying to use pagination in conjunction with the Events app.

I'm also returning the content, and setting it as a Perch variable with PerchSystem::set_var.

The pagination is not working, and the count isn't accurate. Please see my code below:

$important_events = perch_events_custom([
    'template' => '/default/important-event.html',
    'filter' => 'eventDateTime',
    'match' => 'gte',
    'value' => date("Y-m-d"),
    'paginate' => true,
    'count' => 9
],true);
PerchSystem::set_var('important_events',$important_events);

Here's my template:

<perch:if exists="important_event">
    <div class="default_important-event default_upcoming-event">
        <div class="upcoming-event-date">
            <span class="upcoming-event-date-date"><perch:events id="eventDateTime" format="d" /></span>
            <span class="upcoming-event-date-month"><perch:events id="eventDateTime" format="M" /></span>
        </div>
        <div class="upcoming-event-details">
            <h3><span class="event summary <perch:events id="category_slugs" />"><perch:events id="eventTitle" /></span></h3>
            <perch:events id="important_event" type="checkbox" label="Important Event" value="important" suppress="true"/>
            <i class="fa fa-chevron-right"></i>
        </div>
    </div>

    <perch:if exists="paging">
      <div class="paging">
        Page <perch:events id="current_page" type="hidden" /> of <perch:events id="number_of_pages" type="hidden" />
        <perch:if exists="not_first_page">
          <a href="<perch:events id="prev_url" type="hidden" encode="false" />">Previous</a>
        </perch:if>
        <perch:events id="page_links" encode="false" type="hidden" />
        <perch:if exists="not_last_page">
          <a href="<perch:events id="next_url" type="hidden" encode="false" />">Next</a>
        </perch:if>
      </div>
    </perch:if>

</perch:if>

I've tried this without returning the HTML, instead just doing a normal perch_events_custom call, but that doesn't work either. No pagination appears, and the count is incorrect - if I enter '6' for count, I get one result. Entering '9' gets me three results.

Any ideas here?

Harry Ray

Harry Ray 0 points

  • 1 year ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Harry,

the events app doesn't have a paginate option https://docs.grabaperch.com/functions/events/perch-events-custom/

It's quite an old app and doesn't have some of the features of the newer apps.

Hi Duncan,

Thanks for your reply! Bit of a shame that the Events app isn't being kept up to date though, that would've been useful.

Have you got any idea with the count issue that I'm seeing up in my post, too?

Duncan Revell

Duncan Revell 78 points
Registered Developer

I suspect it's because you're filtering in the template too - do only 3 of the 9 items match exists="important_event"?

Try turning on debug and see how many items the sql query returns.

Ah - you're right.

Trouble is that I need to filter by "important_event" and make sure that I'm only fetching future dates.

Apparently the Perch Events app can't filter by multiple fields, so I'm not too sure what I can do here.

Below is my code:

$important_events = perch_events_custom([
            'template' => '/default/important-event.html',
            'filter' => array(
                array(
                    'filter' => 'eventDateTime',
                    'match' => 'gte',
                    'value' => date("Y-m-d")
                ),
                array(
                    'filter' => 'important_event',
                    'match' => 'eq',
                    'value' => 'important'
                ),
            ),
            'sort' => 'eventDateTime',
            'sort-order' => 'ASC',
            'count' => 9
        ],true);
        PerchSystem::set_var('important_events',$important_events);

and my new template:


<div class="default_important-event default_upcoming-event"> <div class="upcoming-event-date"> <span class="upcoming-event-date-date"><perch:events id="eventDateTime" format="d" /></span> <span class="upcoming-event-date-month"><perch:events id="eventDateTime" format="M" /></span> </div> <div class="upcoming-event-details"> <h3><span class="event summary <perch:events id="category_slugs" />"><perch:events id="eventTitle" /></span></h3> <perch:events id="important_event" type="checkbox" label="Important Event" value="important" suppress="true"/> <i class="fa fa-chevron-right"></i> </div> </div>