I'm trying to use the CiviCRM API to show a list of upcoming events (in the confirmation email a user receives when they sign up for an event).

When I try the operation in the API Explorer it appears to return exactly what I want, but when I apply the code (in this case, the Smarty code) in the Message Template, the filtering to only show events after the date specified doesn't seem to take any effect. It just shows all the events.

  $this->assign("param_start_date", array('>' => "2013-10-22 18:00:00"));
  $this->assign("param_options", array('sort' => "start_date"));
{crmAPI var='result' entity='Event' action='get' return="title,start_date" start_date=$param_start_date options=$param_options}
{foreach from=$result.values item=event}

I got the above code using the API Explorer by:

  • Selecting 'Event' as the entity.
  • 'Get' as the method. 'Event Title' and 'Event Start Date' as the Fields to return.
  • 'Event Start Date' as the parameter, with '>' as the operator and '2013-10-22 18:00:00' as the value.
  • Selecting 'Sort' as an option, with value 'start_date'.

1 Answer 1


That's really strange! Just a guess but maybe it's a problem with the way $this->assign works in message templates? I've only tested that construct in smarty pages and message templates might have a different way of processing variables like that.

  • Yeah, I've asked around and apparently one can't use {php} tags within message templates. I got round the problem eventually by creating a custom token in an extension. Mar 14, 2017 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.