Hot answers tagged

10 votes

Escaping quotes in ckeditor breaks smarty-syntax

Go to Administer menu » Customize Data and Screens » Display Preferences, click the Configure CKEditor button and add entities = false in the advanced options (see screenshot). Note: This is the ...
Thomas's user avatar
  • 321
10 votes
Accepted

How to deal with ' or (') in CKeditor

You can turn off html encoding for CKeditor through UI (i.e >= 4.7) Navigate to Administer >> Customize Data and Screens >> Display preferences Scroll down until you see Configure CkEditor button. ...
Pradeep Nayak's user avatar
10 votes

How can I change the date format in a Search Kit result?

You must be on CiviCRM 5.47+ to have the "Use Smarty in Search Kit rewrites" feature. Create a Search Display based on your search - e.g. Add » Table using the Add button in the left pane. ...
Jon G - Megaphone Tech's user avatar
7 votes
Accepted

SMARTY error with template

The styling needs to be wrapped in {literal}...{/literal} in the message template.
Demerit's user avatar
  • 21.7k
6 votes
Accepted

How can I see the available tokens for message templates?

use {debug output=html} To have a nice formatting in html email
empiguet's user avatar
  • 158
6 votes

How can I run a php script to display API response with social media information for a contact

You can run php inside smarty, you just need to include it within {php} tags. {php} $result = doSomethingCool(); $this->assign('coolStuff', $result); {/php} <div>Your social media ...
Coleman's user avatar
  • 17.5k
6 votes
Accepted

How to set a id attribute to button?

I believe you cannot set id to a button using php however you can define your own class for the button and use JS to set the id for that class. Here is the snippet to add class for button $this->...
Pradeep Nayak's user avatar
5 votes
Accepted

How to go about making a Core Tab on the Contact Summary screen view Inline instead?

Rather than smarty, JavaScript will do the trick. Those tabs are all separate pages, and you can load any CiviCRM page/form as a snippet instead. First, in your extension, use a hook to include the ...
Andie Hunt's user avatar
  • 7,442
5 votes

Can I format a smarty token number to have thousands comma?

The civi provided modifier has a different name: crmNumberFormat moreover as per Paul-Tahoe analysis, smarty seems to be confused, so the trick is to assign the formatted value to a temporary ...
Xavier's user avatar
  • 10.2k
5 votes
Accepted

Custom date field formatting with smarty

Found the answer. The civi field token must be captured to a Smarty variable first: {capture assign=arr}{contact.custom_105}{/capture}{$arr|date_format:"%A, %B %e, %Y"}
Phil Morice Brubaker's user avatar
5 votes

How to use Smarty for change greetings for French?

Try below code {capture assign=contact_gender}{contact.gender}{/capture} {if $contact_gender eq 'Female'} Chère {$first_name|default:Friend}, {/if} or {capture assign=contact_gender}{contact....
Pradeep Nayak's user avatar
5 votes
Accepted

Displaying custom contribution field in the online receipt

The smarty variables for online and offline may be different for Contribution ID. For offline {crmAPI var='rname' entity='Contribution' action='getvalue' return="custom_134" id=`$...
Pradeep Nayak's user avatar
4 votes

How can I run a php script to display API response with social media information for a contact

Since you are wanting to do more than just a "little bit" of php in your smarty template I would suggest this alternate approach: Implement a hook that fires when you want, such as ...
Coleman's user avatar
  • 17.5k
4 votes
Accepted

Contribution Note Smarty Variable

I might be missing something but, the contribution.contribution_id variable you are referring as a standalone variable I believe is a token, I can't figure out what's the smarty variable for it but ...
Andrei's user avatar
  • 2,321
4 votes
Accepted

Override TPL path dynamically

Use an extension's templates dir Creating a simple extension via civix provides a templates/ directory in the extension. This is searched before the default templates, so you can intercept and ...
Chris Burgess's user avatar
4 votes
Accepted

Custom Email Greeting token doesn't work

Any chance you don't have smarty enabled for civiMail so your capture-assigns and ifs aren't working in the mail? Try checking your civicrm.settings.php file and look for the line define( '...
Eli Lisseck's user avatar
  • 1,499
4 votes
Accepted

If statement involving "is not empty" in smarty template?

{capture assign=temp}{contact.supplemental_address_1}{/capture} {if $temp ne ""} {$temp} {/if} is what I do. I got the idea from the source referenced above. You also need to ensure that smarty is ...
Mick Kahn's user avatar
  • 3,227
4 votes

How to check if a contact has an active membership in a smarty template?

Don't think you have a direct variable to use in the template. Worth trying an extension to provide this? It can be done by simply writing something like below in your hook. function ...
jitendra - fuzion's user avatar
4 votes

How to check if a contact has an active membership in a smarty template?

You can use CiviCRM api through smarty to retrieve if membership is active for a contact. You can achieve this by Turn on CIVICRM_MAIL_SMARTY (set to TRUE or 1) in civicrm.settings.php add below api ...
Pradeep Nayak's user avatar
4 votes
Accepted

How to use Smarty for change greetings for French?

Thanks to Pradeep's help I found the way: For my case, this is the code to use {capture assign=gender}{contact.gender}{/capture} {if $gender eq 'Homme'} Cher {contact.first_name}, {elseif $gender ...
Guillaume Sorel's user avatar
4 votes
Accepted

Smarty only generating nulls from API calls

So, for posterity's sake, I wanted to share the answer I figured out. When I looked at the Source view of the email in CiviCRM, I realized that the code had pasted as <p>id:&nbsp;{contact....
pyfi's user avatar
  • 81
4 votes
Accepted

Insert file into greeting field with Smarty

The length limit of the greetings syntax can be quite tricky, especially when using different languages with gender specific greetings. Luckily there is the extension More Greetings that provides ...
Fabian's user avatar
  • 3,472
4 votes

Smarty syntax error: unrecognized tag?

Nevermind. I've looked through all of the settings, and it turns out that my colleagues modified the Addresses format but didn't do it correctly. Once this is fixed, everything is back to normal now....
Aaron's user avatar
  • 71
3 votes
Accepted

Smarty and future proof code

Going forward, much of the Civi UI will be written in Angular. However at least 95% of the application uses Smarty and it's still a perfectly acceptable way to mark up a form or page. Depending on ...
Coleman's user avatar
  • 17.5k
3 votes

Scheduled Reminder Email is Empty

For anyone who may face this issue, it was finally fixed by WP Engine through adding an exception on the firewall for CiviCRM cron URL.
Soroush Zo's user avatar
3 votes
Accepted

$participant_status_id shows previous value in email template

This was posted a while ago, but I thought I should post the solution I finally found to the problem (which still exists in my version 4.7.29 install) The solution to this problem was an API call. ...
Jeff Wood's user avatar
  • 133
3 votes
Accepted

How to include price field data in a Contribution Thank You letter

It doesn't work because $lineItem is not set in the template, you'll have to loop thorough $contribtuions and use the API: {foreach from=$contributions item=contribution} {crmAPI var='result' entity='...
Andrei's user avatar
  • 2,321
3 votes

How to get php $_SESSION variable inside a template

Try following: // php code; $_SESSION['test'] = 'Hello World'; // assign 'Hello World' to .tpl $this->assign('test', $_SESSION['test']); // use '{$test}' following in ...
1990rk4's user avatar
  • 483
3 votes

Smarty Template CMS-agnostic URL

{crmURL p="civicrm/points/grant" q="cid=$cid&type=$type"} ^this The p is the address of the page The q is the list of parameters The domain is added first So the above code (with $cid=A and $...
JohnFF's user avatar
  • 2,343
3 votes
Accepted

Smarty code not working

The problem is that the space in the if-statement is &nbsp; rather than a normal space. For this reason, it's worth writing your smarty statements while viewing the Source code in the template ...
Phil Morice Brubaker's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible