0

I try to send a single mail through Contacts > New Mail using a template containing next Smarty instructions:

{if {contact.preferred_language} == "fr_FR"}OK{else}KO{/if}

but these mails cause an error with a very cryptic message:

Error

The website encountered an unexpected error. Please try again later.

EDIT: Thanks to Demerit (see below), I could identify what is working and what not. The smarty code

{capture assign=pref}{contact.preferred_language}{/capture}

{contact.email_greeting} ({contact.preferred_language} = {$pref}?),

is working as expected and gives the expected output

Monsieur (fr_FR = fr_FR?),

So, the {capture}instruction is working, but when I add the instruction below

{if $pref == "fr_FR"}OK{/if}

I get the error message described above and no message is sent.

2
  • Do you mind to paste your smarty code? may be there should be some syntax error in your smarty? Aug 16, 2021 at 13:46
  • @PradeepNayak: Sure, you are right: I should have done that before. I edited my question above to include the code causing the error. Aug 16, 2021 at 17:35

1 Answer 1

3

Thanks for pasting the code: You can't use tokens inside a smarty command like that.

You need to do:

{capture assign=pref}{contact.preferred_language}{/capture}
{if $pref == "fr_FR"}OK{else}KO{/if}
4
  • Now getting "Mailing Error Expected a string or file resource" as error. Aug 17, 2021 at 10:13
  • Where do I have to insert the {capture ...} instruction? Into the body of the HTML text, into the plain text, or into the subject field. I need the variable $pref from the three places. Aug 17, 2021 at 10:20
  • There was als another problem: when I paste the smarty code into an HTML editor, the quotes are changed into entities " that smarty doesn't recognise. Aug 17, 2021 at 11:25
  • There is a setting civicrm.stackexchange.com/questions/7212/…
    – Demerit
    Aug 17, 2021 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.