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) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Custom Smarty variables
Pages: [1]

Author Topic: Custom Smarty variables  (Read 1668 times)

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Custom Smarty variables
February 18, 2013, 02:13:19 pm
I've been able to make my own custom variables for the user dashboard with no problem. (Using a hook to the user dashboard php file and ading the variable I made tot he matching template file.)

What I am having trouble doing now is adding a custom smarty variable to the common/joomla.tpl file. Any suggestions!? ???

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: Custom Smarty variables
February 19, 2013, 08:32:33 am

all the tpl files, share the same smarty instance.

so you can add a custom variable in the hook below and just display it in joomla.tpl

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

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Re: Custom Smarty variables
February 19, 2013, 10:58:05 am
I'm sure I am missing something simple..... I've started with the example from here:
http://civicrm.org/blogs/colemanw/create-your-own-tokens-fun-and-profit

Code: [Select]
function joomla_civicrm_tokens(&$tokens) {
  $tokens['date'] = array(
    'date.date_short' => 'Today\'s Date: mm/dd/yyyy',
    'date.date_med' => 'Today\'s Date: Mon d yyyy',
    'date.date_long' => 'Today\'s Date: Month dth, yyyy',
  );
}

function joomla_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
  // Date tokens
  if (!empty($tokens['date'])) {
    $date = array(
      'date.date_short' => date('m/d/Y'),
      'date.date_med' => date('M j Y'),
      'date.date_long' => date('F jS, Y'),
    );
    foreach ($cids as $cid) {
      $values[$cid] = empty($values[$cid]) ? $date : $values[$cid] + $date;
    }
  }
}

but when I try to call {$date.date_med} in my joomla.tpl file, no dice.......

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: Custom Smarty variables
February 19, 2013, 01:17:22 pm

the token hook is only called on pages that involve tokens (most of them are related to mailings)

to expose something like the below in all tpl files, you can add the template variables in the hook_civicrm_pageRun and hook_civicrm_buildForm and assign them to the template directly:

Code: [Select]
$date = array( 'date_short' => ... );
$template = CRM_Core_Smarty::singleton();
$template->assign_by_ref( 'date', $date);

and in joomla.tpl

Code: [Select]
{$date.date_short}

the code above is approx :)

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

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Re: Custom Smarty variables
February 19, 2013, 04:14:32 pm
Thank you, I had tried page run before but couldn't figure out the assign portion!! This works wonderfully!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Custom Smarty variables

This forum was archived on 2017-11-26.