This documentation refers to CiviCRM 4.1, the current stable version.

Skip to end of metadata
Go to start of metadata


Documentation Search


CiviCRM 4.1 Documentation

Developer Resources


CiviCRM books!

Make sure to check out our Online User/Administrator and Developer Guides! You can also support this project by ordering a hard copy.

Or support us by buying an eBook or hard copy of Using CiviCRM from Packt Publishing.

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