|
You might want to display more information that those that are assigned by default in the template. My goal was to have a simple way of retrieving more information from civicrm than the ones available in the template, without having to modify the php code . For instance, I used it to display all the employees of an organisation from the profile that displays the organisation, or to display a list ofother contacts that live in the same country than the contact you're viewing. The general idea is to be able to use any api method to fetch the content and assign it to a regular smarty variable, so it can then be templated and display how you want it. It simply introduce a new function in the template, "crmAPI". I'm assuming in the rest of this post that you know already where are stored the templates, how to identify the one you want to modify and have a basic knowledge of smarty. If you are familiar with civicrm api v2, it will be fairly straightforward to use and fetch about any type of content existing in civicrm and display it where you want. From anywhere within your template, simply call {crmAPI entity="nameobject" method="namemethod" var="namevariable" extraparam1="aa" extraparam2="bb"}
For example, if you want to display a list of contacts\ {crmAPI entity='contact' action="search" var="contacts"} The extra params allow to filter, for instance only the individual contacts in France, and return only the sort_name and the email. {crmAPI entity='contact' action="search" var="contacts" country="France" contact_type="Individual" return ="sort_name,email"} Another example passing the contact ID smarty variable from the page as a parameter. For this particular API call, the results are in a sub-array called 'result', so to get at them, we loop through "$examplevar.result" instead of "$examplevar". See the api docs - most have an example of the kind of array you will recieve for your call. (If you need more info, use smarty's version of 'print_r' to see what you've been given, e.g. {$activities|@print_r} ) {crmAPI entity="activity" action="get_contact" var="activities" contact_id=$contactId } Numerical array entries: Some API functions presently throw a bunch of results at you without giving them a named key. E.g., get notes gives you an array of body text from your notes and one associative value for the error_key. If you need to loop through numerical array entries like this, Smarty uses a different function, 'Section'. Example: { crmAPI entity="note" action="get" var="notes" entity_table="civicrm_contact" entity_id=$contactId } |
Smarty interface
Labels
