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 CiviMail (Moderator: Piotr Szotkowski) »
  • Using smarty date to put month into a template
Pages: [1]

Author Topic: Using smarty date to put month into a template  (Read 2793 times)

matthewboh

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 2
Using smarty date to put month into a template
May 16, 2012, 07:12:53 pm
Updated - 12:15 PM EST

I went into the civicrm.settings.php file to allow for usage of smarty variables in the message templates. I checked for this line:

define( 'CIVICRM_MAIL_SMARTY', 0 );

... and changed the 0 to 1.

I was then able to use {$smarty.now|date_format} to put the date into the email message.

However, I wanted to put just the month name, so I changed the token to read {$smarty.now|date_format:"%B"}. However, that change to the code generates the following error message:

   
Quote
User error: Smarty error: [in string:

    {$smarty.now|date_format:'%B'}
    line 2]: syntax error: unrecognized tag: $smarty.now|date_format:'%B' (Smarty_Compiler.class.php, line 446) in Smarty->trigger_error() (line 1093 of /var/www/lcfcadmin/sites/all/modules/civicrm/packages/Smarty/Smarty.class.php).
    User error: Smarty error: [in string:

    {$smarty.now|date_format:'%B'}
    line 2]: syntax error: unrecognized tag '' (Smarty_Compiler.class.php, line 590) in Smarty->trigger_error() (line 1093 of /var/www/lcfcadmin/sites/all/modules/civicrm/packages/Smarty/Smarty.class.php).

I have downloaded Smarty 2.6.26, copied the demo to my Apache server and the demo works flawlessly. I also ran a diff against the Smarty_Compiler.class.php in CiviCRM and the same file from http://www.smarty.net and found no differences.

I have tried escaping the quotes, using single quotes, double quotes, back quotes - all to no avail.

It looks like you can't pass any strings to Smarty - should I file this as a bug?

I'm using CiviCRM 4.1.2 on Drupal 7.14

As always, thanks for the help!
« Last Edit: May 18, 2012, 09:33:20 am by matthewboh »

damaxl

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 0
  • CiviCRM version: 4.1.2 DE
  • CMS version: Drupal 7.12 / 7.14
  • MySQL version: 14.12
  • PHP version: 5.2.6
Re: Using smarty date to put month into a template
June 25, 2012, 10:20:46 am
Hello Mathew,

this was my problem also. I found out, that the WYSIWYG-Editor changes the double quotes to " and the single quote into '. You have to click on sourcecode button to see it, because on the surface you will allways see only quotes. This replacement now causes the parser to throw that error.
Using {$smarty.now} alone worked for me, but puts in the date in american format and I need it in german which is 01.02.2012

Max


comff

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
  • CiviCRM version: 4.4.3
  • CMS version: Joomla 2.5.14
  • MySQL version: 5.0.91
  • PHP version: 5.3.28
Re: Using smarty date to put month into a template
August 13, 2014, 07:02:00 pm
I know I am late to the party, but I just wanted to post a work around to this problem since this was pretty much the only thread I found that addressed the issue. HUGE thanks to damaxl for providing the key to this solution.  damaxl is correct, the WYSIWYG editor does indeed change the single quotes into &#39 and I found no way to work around this, however, I did find the module that controls the date_format function, it is the modifier.date_format.php module located in the plugin folder for Smarty.  I am working with Joomla, so I can only give a direct path for Joomla,
which is /administrator/components/com_civicrm/civicrm/packages/Smarty/plugins/modifier.date_format.php. 

At the time of this writing, the line I changed number 31:

function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')

you can replace the '%b %e, %Y' with whatever format you want the function to default to and then just use {$smarty.now|date_format}.  It worked like a charm!  Unfortunately, you have to remember this change every time you upgrade CiviCRM.  So I just added it to my ever growing list!

I hope this helps someone!

gibsonoliver

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 2
    • Northbridge Digital
Re: Using smarty date to put month into a template
August 21, 2014, 01:30:17 am
I've done some tests on a standard Wordpress install using CiviCRM 4.4.6.
The WYSIWYG in use is Tiny MCE

After enabling smarty in the settings.php file the smarty codes seemed to work fine with no further changes required.
All the codes below worked with no issues (tested on a PDF letter).
{$smarty.now|date_format} - will equal Aug 21, 2014
{$smarty.now|date_format:"%B"} - will equal August
{$smarty.now||date_format:"%A, %B %e, %Y"} - will equal Thursday, August 8, 2014
{$smarty.now|date_format:"%e/%m/%Y"} - will equal 21/08/14

Oliver
Oliver Gibson, Northbridge Digital

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • Using smarty date to put month into a template

This forum was archived on 2017-11-26.