Answers.Body: <p>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. <a href="https://github.com/civicrm/civicrm-core/pull/6369" rel="nofollow noreferrer">Here's a fix</a> for both those issues.</p>
  
  <p>The upshot is you can now do this:</p>
  
  <p><a href="https://i.sstatic.net/0zCQQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0zCQQ.png" alt="API Explorer with member params"></a></p>
  
  <p>Instead of the boilerplate <code>{foreach}</code> loop you can do a simpler conditional. Here's the full code you would use:</p>
  
  <pre><code>{php}
    $this-&gt;assign("param_status_id", array('IN' =&gt; 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}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-31T23:23:41.867Z
Answers.Text: contact_id="user_contact_id" was essential.  never seen that before.  thanks!  Where is that documented?
Answers.UserDisplayName: CiviTeacher
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-01T01:31:48.657Z
Answers.Text: Beats me, but now it's the default in the api explorer, nice n easy to find :)
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-31T21:43:23.437Z
Answers.LastActivityDate: 2015-07-31T21:43:23.437Z
Answers.UserDisplayName: Coleman
Body: <p>I've been tinkering with API explorer and examples <a href="https://github.com/civicrm/civicrm-core/blob/4.5/api/v3/examples/" rel="nofollow">https://github.com/civicrm/civicrm-core/blob/4.5/api/v3/examples/</a> but can't find a solution.</p>
  
  <p>Via <strong>Smarty</strong> 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:</p>
  
  <ol>
  <li>a membership of a certain type (example: "1")</li>
  <li>that is "active" (current or new status)</li>
  </ol>
  
  <p>Note that this contribution page is not membership related, it is for donations.  </p>
  
  <p>Can someone please point me in the right direction?</p>
  
Tags: <api>
Title: How do I use the API to check MembershipType and "active" status?
ThreadText: # How do I use the API to check MembershipType and "active" status?
  
  (Asked by: username_0 on 2015-07-31)
  
  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?
  
  **Tags:** api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-31. Score: 2 | Accepted answer
  
  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](https://github.com/civicrm/civicrm-core/pull/6369) for both those issues.
  
  The upshot is you can now do this:
  
  [![API Explorer with member params](https://i.sstatic.net/0zCQQ.png)](https://i.sstatic.net/0zCQQ.png)
  
  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}
  
  ```
  
  > **Comments:**
  > **username_0**: contact_id="user_contact_id" was essential.  never seen that before.  thanks!  Where is that documented?  
  > **username_1**: Beats me, but now it's the default in the api explorer, nice n easy to find :)  
  
  ---
  
  