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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • New feature to easily "embed" a template
Pages: [1]

Author Topic: New feature to easily "embed" a template  (Read 531 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
New feature to easily "embed" a template
March 28, 2012, 08:18:53 am
Hi,

We started this work with kurund at the sprint in London. The goal was to easily add a bit of html into a page after a page is loaded. It's used intensively already (using a different technique) for instance on the contact page, it doesn't load all the tabs when you see the summary, but only when needed (when the user click on the tab)

How does it work? you need to decide what your bit of html will contain, say a list of the memberships of a contact.

Put the template you want in the right place templates/CRM/Member/Page/Inline/MyDemo.tpl

you can then load it in any page with the following snippet

<div id="mydemo"><a id="mytrigger" href="/civicrm/inline/member/my_demo?cid=42">Load the list of membership</a></div>
Code: [Select]
<script>{literal}
cj(function($){
  $('#mytrigger').click (function () {
     $('#mydemo').load ($(this).href);
     return false;
  });
});
{/literal}</script>

Some points:
/civicrm/inline/{entity}/{template_name}
  • loads the template under http:/civicrm/inline/{entity}/{template_name}
  • if you load it using $().load (or any jquery ajax load) it will NOT include the "chrome" (layout/logo/js...) and only the html defined in the template. This is the normal way of using this feature, the normal loading is there mostly because it's way easier to debug
    • if you put an extra param ?xxx=yyy it will be accessible in the template {$xxx}
      It is protected, so if you want to use it for 'html/js...' it is likely it will not work. stick to int & text

    So there is 0 php available. It is meant to be used in conjonction with {crmAPI} to fetch and layout the data you want to display, and use $().crmAPI to modify any content. It isn't meant to be a replacement of the regular forms.

    http://issues.civicrm.org/jira/browse/CRM-9792
    and this is (for now) in http://svn.civicrm.org/civicrm/branches/trunk.profile

    It looks for the template like the other civi pages, so first in your custom template (if defined) then in the core.
    Open questions:
    - should modules be able to easily add more folders to the smarty include path, both for this and to override existing templates?
    - would a hook to inject a bit of php before calling the template be a useful addition (in a future version)

    X+

    X+
« Last Edit: March 28, 2012, 08:47:59 am by xavier »
-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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • New feature to easily "embed" a template

This forum was archived on 2017-11-26.