Answers.Body: <p>You can run php inside smarty, you just need to include it within <code>{php}</code> tags.</p>
  
  <pre><code>{php}
    $result = doSomethingCool();
    $this-&gt;assign('coolStuff', $result);
  {/php}
  
  &lt;div&gt;Your social media profile is: {$coolStuff}&lt;/div&gt;
  </code></pre>
  
  <p>PS instead of hacking the template directly you can add a .tpl.extra file.
  See <a href="https://civicrm.org/blogs/dave-greenberg/now-its-easier-add-custom-behaviors-templates">https://civicrm.org/blogs/dave-greenberg/now-its-easier-add-custom-behaviors-templates</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-30T12:28:40.953Z
Answers.Text: Ok - this is good to know I shall try this!
Answers.UserDisplayName: Caroline B
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-29T22:17:06.783Z
Answers.LastActivityDate: 2015-12-29T22:17:06.783Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>Since you are wanting to do more than just a "little bit" of php in your smarty template I would suggest this alternate approach:</p>
  
  <ol>
  <li>Implement a hook that fires when you want, such as <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pageRun" rel="nofollow">hook_civicrm_pageRun</a>.</li>
  <li>In your hook, run the php code you want to retrieve the remote data (also add a conditional to only run it in the specific circumstance you want, since this is a rather ubiquitous hook - check the page name).</li>
  <li>I might also suggest some form of local caching so you are not firing external rest requests <em>all the time</em>.</li>
  <li>From your hook, inject the content you want into a <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Region+Reference" rel="nofollow">region of the page</a>.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-02T21:46:21.310Z
Answers.Text: Great thanks everyone I've got a lot of pointers here
Answers.UserDisplayName: Caroline B
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-30T16:53:59.447Z
Answers.LastActivityDate: 2015-12-30T16:53:59.447Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>Second the solution from Coleman. If however you do not want to include PHP in a Smarty template you could also create an API in an extension that does what you want to do, and then use CRM.api to retrieve the data in jQuery/JS.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-30T12:29:58.067Z
Answers.Text: I think this is probably beyond my "talents" at the moment however I like a challenge so I may well give it a try! Thank you :)
Answers.UserDisplayName: Caroline B
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-30T10:51:25.493Z
Answers.LastActivityDate: 2015-12-30T10:51:25.493Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>OK so I am interested in displaying social media account information for my contacts. Attentiv.ly looks awesome but very expensive :(( </p>
  
  <p>So I have been investigating other options and can now successfully pass a rest API via a php file to retrieve json from PIPL for a contact. Within civicrm I can create a link to the json using the email variable. I have temporarily (for exploratory purposes only don't worry!) hacked the email.tpl with this </p>
  
  <pre><code>&lt;a href="https://api.fullcontact.com/v2/person.html?email={$item.email}&amp;apiKey=XXXXXX"&gt; social profile&lt;/alink
  </code></pre>
  
  <p>And when clicked it takes me to the correct social mediaprofile. It also works with the Fullcontact API. Hooray!!!</p>
  
  <p>However what I really need is to somehow substitute the link for the script - but I can't put the PHP in the smarty template so now I'm stumped.</p>
  
  <pre><code> //    $curl = curl_init();
   //   curl_setopt ($curl, CURLOPT_URL, "https://api.pipl.com/search/v4/?email=email@email.com&amp;key=xxxxxxxxxxxxxx ");
   //   curl_exec ($curl);
   //  curl_close ($curl);
  ?&gt;
  </code></pre>
  
  <p>Or this </p>
  
  <pre><code>//include_once '../creds.php';
  //include_once '../Services/FullContact.php';
  
  //initialize our FullContact API object
  //get your api key here:  http://fullcontact.com/getkey
  //$fullcontact = new Services_FullContact_API($apikey);
  
  //do a lookup
  //$result = $fullcontact-&gt;doLookup('bart@fullcontact.com');
  
  //dump our results
  //echo "&lt;br/&gt;----------------&lt;br/&gt;&lt;pre&gt;";
  //print_r($result);
  //echo "&lt;/pre&gt;&lt;br/&gt;----------------&lt;br/&gt;\n";
  </code></pre>
  
  <p>Obviously substituting the email for the civicrm email variable.</p>
  
  <p>Or indeed if I am going about this entirely the wrong way I'm all ears!!!!
  All input welcome! Thank you!</p>
  
  <p>PS if anyone can also tell me how to copy and paste code without it actually rendering that would be great</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-12-28T21:42:51.940Z
Comments.Text: See the "help" button in the StackExchange rich text editor when editing questions and answers for instructions on how to format code for legibility.
Comments.UserDisplayName: Chris Burgess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-04T18:13:20.653Z
Comments.Text: It'd be a shame if your work didn't get into an extension at some point, this sounds like an excellent and generally useful thing. I notice that PIPL has a non-profit free option, which also makes it really affordable. Please feel free to contact me if you want some help with that.
Comments.UserDisplayName: Alan Dixon
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-10T23:20:09.023Z
Comments.Text: Hi Alan I'd like to contact you about this - I'm not sure there is a way through this mechanism - can you send me your email address or twitter handle?
Comments.UserDisplayName: Caroline B
Tags: <smarty><social-media>
Title: How can I run a php script to display API response with social media information for a contact
ThreadText: # How can I run a php script to display API response with social media information for a contact
  
  (Asked by: username_0 on 2015-12-28)
  
  OK so I am interested in displaying social media account information for my contacts. Attentiv.ly looks awesome but very expensive :(( 
  So I have been investigating other options and can now successfully pass a rest API via a php file to retrieve json from PIPL for a contact. Within civicrm I can create a link to the json using the email variable. I have temporarily (for exploratory purposes only don't worry!) hacked the email.tpl with this 
   social profile
  And when clicked it takes me to the correct social mediaprofile. It also works with the Fullcontact API. Hooray!!!
  However what I really need is to somehow substitute the link for the script - but I can't put the PHP in the smarty template so now I'm stumped.
   //    $curl = curl_init();
   //   curl_setopt ($curl, CURLOPT_URL, "https://api.pipl.com/search/v4/?email=email@email.com&key=xxxxxxxxxxxxxx ");
   //   curl_exec ($curl);
   //  curl_close ($curl);
  ?>
  
  Or this 
  //include_once '../creds.php';
  //include_once '../Services/FullContact.php';
  
  //initialize our FullContact API object
  //get your api key here:  http://fullcontact.com/getkey
  //$fullcontact = new Services_FullContact_API($apikey);
  
  //do a lookup
  //$result = $fullcontact->doLookup('bart@fullcontact.com');
  
  //dump our results
  //echo "----------------";
  //print_r($result);
  //echo "----------------\n";
  
  Obviously substituting the email for the civicrm email variable.
  Or indeed if I am going about this entirely the wrong way I'm all ears!!!!
  All input welcome! Thank you!
  PS if anyone can also tell me how to copy and paste code without it actually rendering that would be great
  
  **Tags:** smarty, social-media
  
  > **Comments:**
  > **username_1**: See the "help" button in the StackExchange rich text editor when editing questions and answers for instructions on how to format code for legibility.  
  > **username_2**: It'd be a shame if your work didn't get into an extension at some point, this sounds like an excellent and generally useful thing. I notice that PIPL has a non-profit free option, which also makes it really affordable. Please feel free to contact me if you want some help with that.  
  > **username_0**: Hi Alan I'd like to contact you about this - I'm not sure there is a way through this mechanism - can you send me your email address or twitter handle?  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2015-12-29. Score: 6
  
  You can run php inside smarty, you just need to include it within {php} tags.
  {php}
    $result = doSomethingCool();
    $this->assign('coolStuff', $result);
  {/php}
  
  Your social media profile is: {$coolStuff}
  
  PS instead of hacking the template directly you can add a .tpl.extra file.
  See https://civicrm.org/blogs/dave-greenberg/now-its-easier-add-custom-behaviors-templates
  
  > **Comments:**
  > **username_0**: Ok - this is good to know I shall try this!  
  
  ---
  
  ### Answer by username_3 on 2015-12-30. Score: 4
  
  Since you are wanting to do more than just a "little bit" of php in your smarty template I would suggest this alternate approach:
  
  1. Implement a hook that fires when you want, such as [hook\_civicrm\_pageRun](http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pageRun).
  2. In your hook, run the php code you want to retrieve the remote data (also add a conditional to only run it in the specific circumstance you want, since this is a rather ubiquitous hook - check the page name).
  3. I might also suggest some form of local caching so you are not firing external rest requests *all the time*.
  4. From your hook, inject the content you want into a [region of the page](http://wiki.civicrm.org/confluence/display/CRMDOC/Region+Reference).
  
  > **Comments:**
  > **username_0**: Great thanks everyone I've got a lot of pointers here  
  
  ---
  
  ### Answer by username_4 on 2015-12-30. Score: 2
  
  Second the solution from username_3. If however you do not want to include PHP in a Smarty template you could also create an API in an extension that does what you want to do, and then use CRM.api to retrieve the data in jQuery/JS.
  
  > **Comments:**
  > **username_0**: I think this is probably beyond my "talents" at the moment however I like a challenge so I may well give it a try! Thank you :)  
  
  ---
  
  