Hot answers tagged

8

Adding config.entities = false; to the ckeditor-config packages/ckeditor/config.js prevent ckeditor from escaping special characters. This avoids the issue with smarty-syntax. But I am not sure if this doesn't produce other problems by not escaping anything... If anybody has experiences with that please post them here. EDIT: In CiviCRM 4.7 ckeditor will be ...


7

As I learned from @Nicholai in a previous (unrelated) thread, you can override these templates with some pretty easy logic to add something custom to a single page. For example: {if $contributionPageID == 20} {* whatever you need to do on this page *} {/if} I assume this would work in this case, too. If you try it and it works, let us know!


7

Insert {debug} into a message template then perform the relevant action (ie make an online contribution if you modified Contributions - Receipt (on-line)). The email sent will contain a list of all the smarty variables assigned to that template


7

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. Click on it to view all the settings. Under Advance options add entities option as False(as shown in image) and save the form. Note: You will need to clear ...


6

I dont think CiviCRM does this by default However, I do think this is a good idea and makes sense to include it in core for non-civimail mailings (which already have a header/footer) Might want to modify the core mailing functions: CRM_Core_BAO_MessageTemplate::sendTemplate to add a default header / footer Might want to allow this to be overridden both ...


6

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 profile is: {$coolStuff}</div> PS instead of hacking the template directly you can add a .tpl.extra file. See https://civicrm.org/blogs/dave-greenberg/now-its-...


6

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->addButtons([[ 'type' => 'next', 'name' => E::ts('Next'), 'isDefault' => TRUE, 'class' => 'custom_class', //adding class for button )); HTH ...


5

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 variable: {assign var="ttl" value=$contact.total_amount|crmNumberFormat:2:'.':','} and then display it:{$ttl}


5

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 Javascript and provide the contact ID for it: $r = CRM_Core_Resources::singleton() // Provide the contact ID (assuming you've got it handy) $r->addVars('...


5

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.gender}{/capture} {assign var='contact_greeting' value='Dear'} {if $contact_gender eq 'Female'} {assign var='contact_greeting' value='Chère'} {/if} {$...


4

You can insert the {debug} Smarty token into your template: http://forum.civicrm.org/index.php/topic,14845.msg63471.html#msg63471


4

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 hook_civicrm_pageRun. In your hook, run the php code you want to retrieve the remote data (also add a conditional to only run it in the specific circumstance you want, since this ...


4

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 you can do this (it works): {capture assign='id'} // the variable {contribution.contribution_id} // here is the Contribution ID token {/capture} And then ...


4

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 provide your own. If that doesn't go far enough & you want to dynamically select a template (eg replace Form.php, but only when foo=123), these options are ...


4

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( 'CIVICRM_MAIL_SMARTY', 1 ); as per https://backofficethinking.com/blog/tip-how-personalize-emails-civicrm. If you don't find it, or if it's set to 0, you'll need to add/...


4

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 yourextension_civicrm_postProcess($formName, &$form) { if ($formName == "your_form") { //Check if user has an active membership of type "General". $...


4

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 snippet in your message template ($result will hold result of api call) {capture assign=contactId}{contact.contact_id}{/capture} {crmAPI var='result' entity='...


4

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 eq 'Femme'} Chère {contact.first_name}, {/if} I just needed to insert it where needed in the source of the email. FuzionFields was of a good help to find the ...


4

The styling needs to be wrapped in {literal}...{/literal} in the message template.


3

Try following: // php code; $_SESSION['test'] = 'Hello World'; // assign 'Hello World' to .tpl $this->assign('test', $_SESSION['test']); // use '{$test}' following in .tpl file to display on Thank you page, For e.g <tr> <td>{$test}</td> // this will print 'Hello World' on page </tr&...


3

The template ​templates/​CRM/​Contact/​Page/​Inline/ContactName.tpl does not contain any custom fields. Instead of adding smartyDebug=1 in the url, which dumps variables in the main template, try adding the smarty tag {debug} in this specific template to see the available local variables. At minimum you will probably find the contact id, and from there you ...


3

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='LineItem' action='get' contribution_id=$contribution.id} {foreach from=$result.values item=lineitem} {$lineitem.label} // Price field label {/foreach}...


3

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. While the value of $participant_status_id shows the value PRIOR to update, with this Smarty code added somewhere near the top of the template: {crmAPI var='...


3

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.


3

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 your use case you may be able to create an Angular page for what you want. If you are writing an extension, you can try both. Use civix generate:page or civix ...


3

{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 $type=B) translates into: http://example.org/civicrm/points/grant?cid=A&type=B


3

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 editor.


3

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"}


3

You will need to turn on CIVICRM_MAIL_SMARTY in civicrm.settings.php to use smarty templating for conditional and more complex logic. Cheers Pradeep


3

As a workaround for the specific example in your post, you can create a custom token. This post explains how using hook_civicrm_tokens and hook_civicrm_tokenValues


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