2

I've been tinkering with API explorer and examples https://github.com/civicrm/civicrm-core/blob/4.5/api/v3/examples/ but can't find a solution.

Via Smarty I'm looking to print some text "blah blah blah" via the .tpl of a Donation (Contribution) Page if the current viewer of that page has:

  1. a membership of a certain type (example: "1")
  2. that is "active" (current or new status)

Note that this contribution page is not membership related, it is for donations.

Can someone please point me in the right direction?

2

I assuming you're doing this with a .tpl.extra file. I tried mocking this up in the API Explorer and found a couple shortcomings, namely the lack of support for arrays in smarty, and the inability to set a contact ID field to the magic "user_contact_id" value. Here's a fix for both those issues.

The upshot is you can now do this:

API Explorer with member params

Instead of the boilerplate {foreach} loop you can do a simpler conditional. Here's the full code you would use:

{php}
  $this->assign("param_status_id", array('IN' => array("New", "Current", "Grace")));
{/php}
{crmAPI var='result' entity='Membership' action='get' contact_id="user_contact_id" membership_type_id=1 status_id=$param_status_id return="id"}
{if !empty($result.values)}
  Blah blah blah...
{/foreach}
  • contact_id="user_contact_id" was essential. never seen that before. thanks! Where is that documented? – CiviTeacher Jul 31 '15 at 23:23
  • 1
    Beats me, but now it's the default in the api explorer, nice n easy to find :) – Coleman Aug 1 '15 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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