You are here: Home / Documentation / How To's / How to display only certain event types in a portlet

How to display only certain event types in a portlet

by nguyen — published Sep 13, 2008 02:15 PM, last modified Aug 16, 2016 10:50 AM
if you have different event types on your site

See UARC site - classic events portlet, combined with cloned Event portal types or Events that have a specific keyword (category) assigned

Distinguishing between event types: 

There are two ways to distinguish between event types.  Let's say for example you want to have "advisor" and "student" event types.

Use Keyword/Categories

When you create an Event, use the Category tab and set a category "studentevent" or "advisorevent".

Clone the Event portal type

Using the ZMI, go to portal_types, copy and paste the Event type, rename the new Event copy to "StudentEvent".  Do the same to create a "AdvisorEvent" portal type.

Create a portlet to display a specific event type:

Now you want to have a portlet that shows just one event type.  For this example, let's assume it's advisor events.

If you use the keyword/category method:

The events you want to display in the portlet will have the keyword/category "advisorevent".  You will

  • add a page template defining the advisor event portlet
  • add a script that returns published advisor events
  • add a classic portlet that calls the advisor event portlet

In ZMI, go to portal_skins/custom, add a Page Template, give it a name like "portlet_advisor_events".  The body should contain this:

<html xmlns:tal=""
<div metal:define-macro="portlet"
     tal:define="view context/@@events_view;
                 results context/published_advisorevents;
                 events_link view/all_events_link;
                 prev_events_link view/prev_events_link"
<dl class="portlet" id="portlet-events">
    <dt class="portletHeader">
        <span class="portletTopLeft"></span>
        <a href=""
           tal:attributes="href events_link"
            Advisor Events
        <span class="portletTopRight"></span>
    <tal:events tal:repeat="obj results">
    <dd class="portletItem"
        tal:define="oddrow repeat/obj/odd"
        tal:attributes="class python:test(oddrow, 'portletItem even', 'portletItem odd')">
        <a href="#"
           tal:attributes="href obj/getURL;
                           title obj/Description">
            <img src="#" alt="" tal:replace="structure here/event_icon.gif" />
            <span tal:replace="obj/pretty_title_or_id">
             Some Event 
            <span class="portletItemDetails">
                <tal:condition condition="obj/location">
                    <tal:location content="obj/location">Location</tal:location>, <br />
                <tal:date content="python:toLocalizedTime(obj.start)">
                May 5
    <dd class="portletFooter"
       <a href=""
           tal:attributes="href prev_events_link"
            <span i18n:translate="box_previous_events">
                Previous events&hellip;
    <dd class="portletFooter">
        <a href=""
           tal:attributes="href events_link"
                Upcoming events&hellip;
        <span class="portletBottomLeft"></span>
        <span class="portletBottomRight"></span>

You will also need to add a Script (Python) called "published_advisorevents" containing this:

from Products.CMFCore.utils import getToolByName
portal_catalog = getToolByName(context, 'portal_catalog')
return portal_catalog.searchResults(portal_type='Event',
                                    end={'query': DateTime(),
                                         'range': 'min'},

In a normal view (non-ZMI) of the root folder of your site, click on the "Manage portlets" link.  Add a classic portlet.  For Template, specify the value "portlet_advisor_events".  For Macro, specify the value "portlet".  Press Save.  Return to the normal view of your site's home page.  You should now see a new portlet that displays only advisor events.

If you used the portal type method:

If instead you have cloned the Event portal type to one called AdvisorEvent, you can use the same technique as above.  The only difference is in the Script (Python) called "published_advisorevents".  It should contain this

from Products.CMFCore.utils import getToolByName
portal_catalog = getToolByName(context, 'portal_catalog')
return portal_catalog.searchResults(portal_type='AdvisorEvent',
                                    end={'query': DateTime(),
                                         'range': 'min'},

The difference in the script is that instead of specifying


it specifies


It also omits the condition


(the Subject being the internal name for the keyword/category mechanism).