CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • General Discussion (please no support requests here!) (Moderator: Michał Mach) »
  • CRMAPI in Smarty
Pages: [1]

Author Topic: CRMAPI in Smarty  (Read 1306 times)

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
CRMAPI in Smarty
April 04, 2013, 02:01:56 pm
One of my favourite moments is realising an opinion I hold is wrong.

I had a long-standing grudge against working in CiviCRM's Smarty templates from early CiviCRM days, but a few days ago I was asked by a client to give him a little tuition on how to add to the contact summary template to show the member's membership type, status and join date.

{crmapi} syntax made this really easy to throw together quickly, and he was happy to take it from there. I was impressed.

Smarty, I still think you're a bit weird, but you're not half as bad as I thought. Well done CiviCRM team! Thanks.
@xurizaemon ● www.fuzion.co.nz

developer

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 4.2+
  • CMS version: drupal 7.x/6.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CRMAPI in Smarty
April 10, 2013, 07:00:41 am
yes it is. specially the way ajax/doc is simply superb to get the php, smarty and Jquery codes in one go :)

you are really interesting Civi :)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: CRMAPI in Smarty
April 10, 2013, 01:40:55 pm
I'm hopeful that for 4.4 we will be able to add things to screens using regions - which will take us further from smarty over-rides

http://wiki.civicrm.org/confluence/display/CRMDOC43/Region+Reference
http://issues.civicrm.org/jira/browse/CRM-12023

(I have backported the proposal I put up into 4.2 & will do so for 4.3 too because at least it makes adding stuff to the summary screen portable between our customers & I only have to maintain a very minor customisation in our main deployment repo)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: CRMAPI in Smarty
April 10, 2013, 09:55:35 pm
Thanks for the compliments, glad to see it's useful and appreciated

Another trick added on {crmAPI} I find handy: if you omit the var param, it returns the result as a json. If you need the data for js, it saves you an extra request compared to (ab)using CRM.api, eg

Code: [Select]
<script>
var contact={crmapi entity="contact" id=$cid action="getsingle" return="last_name,email"};//never ever do a contact.get without defining what fields you want
// now the javascript var contains the data from the api, ready as soon as you load the page

As for the region, another workaround that works fine (eg. when using {crmapi} from a .extra.tpl) is to use jQuery to move the html generated to the position you want.

eg
Code: [Select]

<div id="extrastuff">
//lots of content fetched with crmapi and put here
</div>
<script>
{literal}
cj(function($){
  if ($("#crm-demographic-content").length == 0)
    return;
  $("#extrastuff").appendTo("#crm-demographic-content");// and moved within the content
});
</script>
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • General Discussion (please no support requests here!) (Moderator: Michał Mach) »
  • CRMAPI in Smarty

This forum was archived on 2017-11-26.