Displaying remaining participant slots on events

Published
2013-07-03 21:01
Written by
ChrisChinchilla - member of the CiviCRM community - view blog guidelines

I'm currently undertaking a vast overhaul of how our site (greenrenters.org) displays and handles events as they are our main interaction point with the public. I'll document what I learn in a series of blog posts and here's the first.

Some say that showing what's left to people motivates them more to take action and do something, wethere or not you think that's true is a completely different story, but here's some code to add (probably in a locally overriden 'CRM/Event/Page/EventInfo.tpl' file). For teh below to work, you need to have maximum participants on an event enabled.

{crmAPI var="ParticipantS" entity="Participant" action="get" sequential="1" event_id=$event.id }
// Gets the current particiapnst registered for the event

{* $x=$event.max_participants, $y=$ParticipantS.count *}
// Assigns our variables for the calculation below

Remaining - {math equation="x - y" x=$event.max_participants y=$ParticipantS.count}
// Subtract the current particpants from the maximum.

Comments

Hi,

 

thanks for sharing, two suggestions:

 

you can use getcount instead of get and you directly get the number you want

instead of modifying CRM/Event/Page/EventInfo.tpl simply create a CRM/Event/Page/EventInfo.extra.tpl with the smarty and add a bit of jquery to move it into the right place in the page, easier to maintain

 

X+

 

the getcount is a good call (will update), I'm not 100% sure if moving things around the page with jquery is the best option… Yet. Depends what I want to do with it later.