Announcement

Collapse
No announcement yet.

Conditions in E-Mail Templates (again)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conditions in E-Mail Templates (again)

    I would like to include simple conditions in a mail template. The documentation says that you can use the same logic as for PDF creation. Nevertheless, the following condition does not work in the template:

    {{#ifEqual Person.salutationName 'Mr.'}}
    <p>Dear Mr. {Person.lastName}</p>
    {{/ifEqual}}

    If I enter {Person.salutationName} in the template, I get Mr. correctly. The problem must therefore lie with the #ifEqual clause. But why? It must be a standard feature of a CRM to be able to send personalized emails.

    Any help really appreciated!
    Andreas

  • #2
    Hi penzelan,

    Please try to use the following example in your email template code:
    Code:
    {{#ifEqual salutationName 'Mr.'}}
    <p>Dear Mr. {Person.lastName}</p>
    {{/ifEqual}}

    Comment


    • #3
      Great, that worked!
      Thank you

      Comment


      • #4
        Originally posted by lazovic View Post
        Hi penzelan,

        Please try to use the following example in your email template code:
        Code:
        {{#ifEqual salutationName 'Mr.'}}
        <p>Dear Mr. {Person.lastName}</p>
        {{/ifEqual}}
        Dear community,
        if I try it that way, all the "{{" "}}" are printed in my email.
        Do I have to do any special thing to "enable" the if-statements? Do I have to pass the entity somehow (its a custom entity to send the mails to and using the fileds)

        Comment


        • #5
          I had the problem when I entered the conditions in design mode.
          Try entering the formula in the HTML code.​

          Click image for larger version

Name:	image.png
Views:	45
Size:	12.4 KB
ID:	110924

          Comment


          • #6
            Originally posted by ChrisSka83 View Post
            I had the problem when I entered the conditions in design mode.
            Try entering the formula in the HTML code.​

            Click image for larger version  Name:	image.png Views:	0 Size:	12.4 KB ID:	110924
            I did that but sadly no difference.
            Here the code:
            Code:
            <p>{CPatient.geschlecht}&nbsp;{CPatient.nachname}< br></p>
            
            {{#ifEqual CPatient.geschlecht 'weiblich'}}
            <p>Sehr geehrte Frau {CPatient.nachname}</p>
            {{/ifEqual}}​
            Here the printout in the E-Mail (code view):
            Code:
            <p>weiblich&nbsp;Mustermann<br></p>
            
            {{#ifEqual CPatient.geschlecht 'weiblich'}}
            <p>Sehr geehrte Frau Mustermann</p>
            {{/ifEqual}}​
            Still printing the "{{" and "}}" instead of executing the logic.

            Any idea?

            Comment


            • Corak
              Corak commented
              Editing a comment
              Yes, HTML activated and received correctly. Just the code isn't executed.

            • ChrisSka83
              ChrisSka83 commented
              Editing a comment
              Ever tried it without the CPatient?

              {{#ifEqual geschlecht 'weiblich'}}
              <p>Sehr geehrte Frau Mustermann</p>
              {{/ifEqual}}​

            • Corak
              Corak commented
              Editing a comment
              Dear Chris,
              thank you for the input. I tried also
              Code:
              {{#ifEqual geschlecht 'weiblich'}}
              <p>Sehr geehrte Frau Mustermann</p>
              {{/ifEqual}}
              but the result was the same, just confirmed it again.
              I am spooked by the brackets too, even if the logic was incorrect these winged "{{" and "}}" shouldn't appear. Is there maybe anything wrong with the syntax?

              And now it looks like we are coming closer: I tried the same with another entity of type "account", not my custom-tailored "CPatient" of type "Basis" (with a hand-added email-type field). And this time the code is executed. So the system seems to refuse to work with my entity at this place. Any idea how to pass my entity to that email-form so the code will be executed?

          • #7
            I also have this query in a few mail templates. It works for me.
            The only difference between me and you is that you use the custom prefix. So the C in CPatient. I deactivated this straight away. Although I already had most of the entities before the introduction.

            yuri
            Could it be the custom prefix?
            Excuse me if I'm linking you.​

            Comment


            • ChrisSka83
              ChrisSka83 commented
              Editing a comment
              As of EspoCRM version 8.2, the letter C is placed in front of every entity and field you create. The reason can be found on the following page:
              When creating fields, links and entity types, a prefix will be automatically added. MyEntity => CMyEntity myField => cMyField (only for non-custom entity types) myLink => cMyLink (only for non-cust...


              You can deactivate it in config.php in the data folder:
              'customPrefixDisabled' => true

              Entities and fields that have already been created are not affected after deactivation. The C remains at the front.
              You would have to delete these first and then create them again.

            • Corak
              Corak commented
              Editing a comment
              Thank you for the note how to deactive. Unfortuantely its not an option to delete and re-create the entity (there are hundreds of fields, relations and data input).
              Any clue to alter the processing (to handle them like non-custom entities) or maybe another way?

            • ChrisSka83
              ChrisSka83 commented
              Editing a comment
              You could export the old entity, create a new one and then import the data again.
              I can't tell you whether you can change this in the files. I would also advise against it if you're not that good at it.
              I would first test whether it is due to the c by creating a new similar entity and just testing whether it was due to that.
              Just one data set is enough, and that is what you need for the mail.
              That's how I would do it to rule it out.
          Working...
          X