This documentation relates to CiviCRM version 3.2. It's not maintained anymore.
Current version of documentation.

Call civicrm apis from the template

Skip to end of metadata
Go to start of metadata

This page refers to outdated version of CiviCRM. Check current version of documentation.


Documentation Search


CiviCRM 3.2 Documentation

Support and Participation

Developer Resources


CiviCRM book!

Make sure to check out Understanding CiviCRM as well! You can also support this project by ordering a hard copy.

This is implemented in 3.0, but you can backport it to 2.2 by copying the file CRM/Core/Smarty/plugins/function.civicrm_api.php

You might want to display more information that those that are assigned by default to the template.

For instance, you might want to display the related contacts from within a profile, or all her/his activities... Anything that can be accessed through the api can be displayed from any template.

If you are familiar with civicrm api v2, it will be fairly straightforward to use. From anywhere within your template, simply call:

* entity is the content you want to fetch, eg. "contact", "activity", "contribution"...

  • action is get, search, search_count (is shouldn't be a method that modify the entity, only to fetch data
  • var is the name of the smarty variable you want to assign the result to (eg the list of contacts)
  • extraparams (optional) all the other parameters (as many as you want) are simply used directly as the "params" to the api. cf. the example below
  • return (optional). The convention to define the return attributes (return.sort_name return.country...) doesn't work with smarty and is replaced by return="attribute1,attribute2,attribute3.."

For instance, is you want to display a list of contacts

The extra params allow to filter, for instance only the individual contacts in France, and return only the sort_name and the email.

Labels
  • None

Creative Commons License
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-Share Alike 3.0 United States Licence.