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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • [SOLVED] Using the hook civicrm_tabs
Pages: [1]

Author Topic: [SOLVED] Using the hook civicrm_tabs  (Read 712 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
[SOLVED] Using the hook civicrm_tabs
October 23, 2012, 04:12:45 am
I have implemented the hook "civicrm_tabs", which mostly works.  The main issue is that the contents of my new tab includes the entire Drupal page ( standard headers, footers, etc) in addition to the output of my function.   I would like the custom tab to only display the output of my function.    ( BTW: This works 100% under Drupal 6, am only running into this issue on Drupal 7)  I have been reading the article at: http://drupal.org/node/223440, but no luck so far.

The URL for the custom tab is: "civicrm/contact/mycoolsummarytab"

I created a new file called "civicrm-contact-mycoolsummarytab.tpl.php" and placed it in my theme folder.

Any ideas on where I should be placing/naming my custom tpl file?
« Last Edit: October 28, 2012, 10:04:56 am by Coleman Watts »
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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 the hook civicrm_tabs
October 23, 2012, 04:48:12 am
if you return the content of the template, it displays it with the theme, if you echo it it doesn't.

Tip: you can test if it's an ajax call (like for a tab) with HTTP_X_REQUESTED_WITH. With the following code, you can have the same template displayed as a normal page (with the full layout) or without any chrome (for ajax). It makes it way easier to debug!

Tip 2: if your template is "simply" about displaying a few things you can fetch with the api without any calculation, you can put in your extension
templates/CRM/Contact/Page/Inline/Mycoolsummarytab.tpl
 (that contains the {crmAPI you need}

and you got it on http://example.org/civicrm/inline/contact/mycoolsummarytab?contact_id=42
(no need to alter the menu or add an xml something, just works)
http://issues.civicrm.org/jira/browse/CRM-9792


Code: [Select]
// from CRM/Utils/REST.php
    if  ( ! array_key_exists ( 'HTTP_X_REQUESTED_WITH', $_SERVER ) ||
      $_SERVER['HTTP_X_REQUESTED_WITH'] != "XMLHttpRequest"  )  {

        $smarty->assign( 'tplFile', $tpl );
        $config = CRM_Core_Config::singleton();
        $content = $smarty->fetch( 'CRM/common/'. strtolower($config->userFramework) .'.tpl' );

        if ($region = CRM_Core_Region::instance('html-header', FALSE)) {
          CRM_Utils_System::addHTMLHead($region->render(''));
        }
        CRM_Utils_System::appendTPLFile( $tpl, $content );

        return CRM_Utils_System::theme( 'page', $content, true);

      } else {
        $content = "<!-- .tpl file embeded: $tpl -->\n";
        CRM_Utils_System::appendTPLFile( $tpl, $content );
        echo $content . $smarty->fetch ($tpl);
        CRM_Utils_System::civiExit( );
    }
  }
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Using the hook civicrm_tabs
October 23, 2012, 06:58:34 am
Thanks for the tips.   It turns out the only thing I needed to add to my function was this 1 line:
CRM_Utils_System::civiExit( );

Then the tab displayed correctly.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • [SOLVED] Using the hook civicrm_tabs

This forum was archived on 2017-11-26.