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) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Can we contribute the .tpl files for a drupal module
Pages: [1]

Author Topic: Can we contribute the .tpl files for a drupal module  (Read 1827 times)

mbabar86

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: 7
  • MySQL version: 4
  • PHP version: 5
Can we contribute the .tpl files for a drupal module
October 15, 2012, 07:45:43 am
Hi guys!

I create a drupal module which need modification in civicrm tpl files.
So what i want is when someone download the module from (Drupal.org) can also grab the modified .tpl files from civicrm community.
Is it possible to contribute the tpl files only.
IF yes(Please guide to the right path)

Happy coding.
Thanks in advance :)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Can we contribute the .tpl files for a drupal module
October 15, 2012, 08:53:55 am

any reason why you dont package the .tpl files within your drupal module?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Can we contribute the .tpl files for a drupal module
October 15, 2012, 09:49:14 am
I think that was the question -- how does one package a .tpl within the module.

1) To answer the immediate question, the module needs to register itself with Smarty's template engine. Here's an example from a module that dlobo wrote:

https://github.com/dlobo/org.civicrm.module.cividiscount/blob/master/cividiscount.php#L30

If you are trying to overload a tpl file, then order of items in the $templates->template_dir array is significant.

(Note: This step is handled automatically if you're writing a CiviCRM Extension-Module using "civix".)

2) Overloading a template often isn't a good idea -- it makes it harder to maintain. (For example, you might overload the template for Civi 4.2 -- but then upgrading to Civi 4.3 becomes a problem because the core version of the template has changed.) A better technique is to keep the original template but dynamically append some code to the page. For modules, a better approach is:

http://wiki.civicrm.org/confluence/display/CRMDOC42/Region+Reference

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Can we contribute the .tpl files for a drupal module
November 05, 2012, 04:31:17 pm
I hope it's ok if I kick at this topic for a moment or two as it is relevant to an extension module that I am tinkering away at.

I am trying to move a hack that I made to civiCRM into an extension module. In my hack solution I copied and modified templates for membership and events registration as well as well as the membership block template:

Contribute -> MembershipBlock.tpl

Event -> EventInfo.tpl 

Event -> Register.tpl



All I did was add a line after the cost token to say "hey this is taxable"; ie:  Plus Harmonized Sales Tax (HST).

I'm using civix to stub out my extension module. Can you give me any tips about how I can achieve this without overriding templates?

Thanks,
Andrew

 
My CiviCRM Extension Workshop: https://github.com/awasson

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Can we contribute the .tpl files for a drupal module
November 07, 2012, 08:45:02 am
One approach is to use jQuery to inject the markup. For example, if there's a div called "crm-my-parent-tag" and you want to add an extra field to the bottom, then you can do something like:

Code: [Select]
cj('.crm-my-parent-tag').append('<div>My new element!</div>')

For example, suppose you implement hook_civicrm_buildForm and want to add a new input to form. You can add the jQuery code to the appropriate page using the Region API

Code: [Select]
function mymodule_civicrm_buildForm($formName, $form) {
  if ($formName == 'CRM_Example_Form') {
    $form->add('text', 'hst', ts('HST'), ...);
    CRM_Core_Region::instance('page-footer')->add(array(
       'jquery' => "cj('.crm-my-parent-tag').append('<input name=\'hst\'>')",
    ));
  }
}

That may not be a fully working example, but you can find more detailed discussion of the 'buildForm' hook and the 'CRM_Core_Region' API here:

http://wiki.civicrm.org/confluence/display/CRMDOC42/Region+Reference
http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Can we contribute the .tpl files for a drupal module
November 07, 2012, 10:36:17 am
Thanks totten! Second time today you've come through for me!

That will be a very handy method as I do like to use jQuery often. I've figured out how to include my own templates in my extension module to override the OEM civiCRM ones. I think for something like this I'm more comfortable adding the notices on the server rather than via jQuery but I'll definitely be using jQuery in other areas; maybe not with this one but I'm just getting started with extensions and I have a bit of a list of items I want to create.

On a side note: One of the reasons I was having trouble adding overriding templates to my extension was because civix configures everything for you (inside myextension.civix.php) and I was busy undoing various things that were already working fine. All I needed to do was add my templates to the template directory in my extension being careful to match civiCRM's established paths and my templates would override civiCRM's. Unfortunately for me, I didn't understand that the first time through and I started messing with the path. Fortunately my work generated a few PHP notices and had the good sense to undo my meddling and all of a sudden my templates were doing what they were supposed to. Civix is pretty fantastic!

Cheers,
Andrew 
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Can we contribute the .tpl files for a drupal module

This forum was archived on 2017-11-26.