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) »
  • Using .extra.tpl files for Contributions
Pages: [1]

Author Topic: Using .extra.tpl files for Contributions  (Read 2524 times)

quackofalltrades

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Using .extra.tpl files for Contributions
August 01, 2011, 02:45:48 pm
So I'm trying to use those .extra.tpl files to append some code to the new contributions form.  I've set up my custom directory and created my file at CRM\Contribute\Form\Contribution.extra.tpl.  My test code is as follows:

Code: [Select]
{literal}
<script>
alert('test');
</script>
{/literal} 

The weird thing is that the same code in CRM\Contact\Form\Contact.extra.tpl works just fine.  Any ideas on what's going on?

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Using .extra.tpl files for Contributions
November 10, 2011, 08:26:27 am
I'm bumping this thread because I'm having the same problem. The .extra.tpl mechanism, which works for Contact forms, does not seem to work for Contribution forms, e.g. templates/CRM/Contribute/Form/Contribution.extra.tpl. Anyone else? Any idea why? Thanks.

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: Using .extra.tpl files for Contributions
November 10, 2011, 09:45:50 am

what page r u trying to modify? i.e. can u let us know the url, u can obfuscate the site name

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

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Using .extra.tpl files for Contributions
November 15, 2011, 03:42:00 am
Hi Lobo,

The page I'm trying to modify is the main Contribution edit form; www.my-crm.org/civicrm/contact/view/contribution?reset=1&action=update&id=109899&cid=548654&context=contribution (for any value of id, cid and context).

I have created a file in my custom templates directory called CRM/Contribute/Form/Contribution.extra.tpl but for some reason the code does not get included in the page above. I also tried CRM/Contribute/Form/Contribution/Main.extra.tpl but that didn't work either.

Like the original poster above, when I created a file CRM/Contact/Form/Contact.extra.tpl, that did get appended to the main Contact form.

Any idea what the problem is? Am I naming the file incorrectly or does the .extra.tpl mechanism not work for the Contribution form?

Thanks.

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: Using .extra.tpl files for Contributions
November 15, 2011, 07:08:34 am

can u add your extra code in this file:

CRM/Contribute/Page/Tab.extra.tpl

if u only want it to appear for the 'edit/create' case, u'll also need to add a conditional:

Code: [Select]
{if $action eq 1 or $action eq 2} {* add orupdate *}
  -- add your code here
{/if}

The reason is there are a few pages across civicrm which get called via one url (civicrm/contact/view/contribution) but do different things based on the action parameter. Hence the main tpl file is different than what u'd expect

We are moving away from that pattern slowly

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

Kirk

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 2
  • CiviCRM version: 4.5.8
  • CMS version: Drupal 7.39
  • MySQL version: 5.5.44
  • PHP version: 5.6.13
Re: Using .extra.tpl files for Contributions
November 16, 2011, 08:45:06 am
Lobo, thank you very much for your help. Your solution worked. Feeling grateful for your help, I went to make a donation to the CiviCRM project on behalf of our organisation, but a bug in the donation form prevented me from doing so!

If you go to donate money to the project-at-large (http://civicrm.org/civicrm/contribute/transact?reset=1&id=19), tick the box that says "I am contributing on behalf of an organization", select any country other than the United States, fill in all required fields including State/Province, then click Confirm Contribution, you'll see that on the next page, the State/Province value has been blanked. Try to Continue and you'll get an error message saying "State / Province is a required field."

In other words, it is impossible to contribute to the project-at-large on behalf of an organisation that is not based in the US! As soon as this bug is fixed, let me know and you can have some dollars. :)

Thanks.

Deepak Srivastava

  • Ask me questions
  • ****
  • Posts: 677
  • Karma: 65
Re: Using .extra.tpl files for Contributions
November 17, 2011, 01:37:13 am
Hey Kirk,

thanks for notifying us. The State/Province problem has been fixed.
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Using .extra.tpl files for Contributions
August 28, 2012, 05:26:15 am
Hi,
I want to add "extra" features to the main Contribution form (add or update), so adding JS to the file CRM/Contribute/Page/Tab.extra.tpl works fine but he Javascript code is executed several times (in my case 2 times).

I think the Tab.tpl is included more than 1 time in the Contribution Form (I couldn't figure out where is called exactly), so any Javascript added is executed as many times as Tab.tpl page is called
Easy test added an alert(''X"); and I see 2 times the alert.

Any ideas?
Tx

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using .extra.tpl files for Contributions
August 28, 2012, 07:12:01 am
Yeap, one of the limitation of the extra.tpl

I tend to "flag" that my custom script has already run, eg

Code: [Select]
cj(function($) {
  if ($(document).data('featureX'))
    return:
  $(document).data('featureX','ready');
  //do the init
});
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Using .extra.tpl files for Contributions
August 28, 2012, 07:24:54 am
Ok, that's what I fear :)
Another useful JS tip it's if you are defining functions inside the extra.tpl and you want to know if the function it's defined already (in the previous execution of the tpl).
Can use this for global functions:

Code: [Select]
if(typeof myfunction != 'function'){
   window.myfunction = function(){
       
      // put your function code here....
   };
}



Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Using .extra.tpl files for Contributions

This forum was archived on 2017-11-26.