progressivetech / com.aghstrategies.petitionemail

an extension that will allow the sending of emails to legislators and newspapers
Other
0 stars 2 forks source link

line breaks in html email message template #3

Closed jmcclelland closed 2 years ago

jmcclelland commented 2 years ago

Thanks @mattwire for adding the template functionality! I found and fixed a few minor bugs when testing but there's one problem I can't figure out how to resolve: The HTML template does not render line breaks in tokens.

We use a token for both the contact info (name, email, postal address) that gets inserted at the top of the email message. And also a token for the entire email message itself. Both of these are chunks of text that should be displayed with line breaks. But, HTML ignores line breaks so they are displayed as one continuous line.

I tried adding nl2br when setting the tokens, but somewhere along the line those get turned into html entities. Any suggestions?

mattwire commented 2 years ago

I did something similar on a site recently using smarty to escape a string like this:

<p>{capture assign=eventTitle}{event.title}{/capture}</p>
<p>Feedback link:
<a href="https://www.example.org/feedback?event_id={event.id}&amp;firstname={contact.first_name}&amp;lastname={contact.last_name}&amp;email={contact.email}&amp;eventname={$eventTitle|escape:'url'}">here</a>
</p>

In theory that could work for the nl2br as well? You have to assign the token to a smarty var so it can then be parsed through the smarty function. A bit messy and would be much better if we had support for more token modifiers like this: https://docs.civicrm.org/user/en/latest/common-workflows/tokens-and-mail-merge/#date

jmcclelland commented 2 years ago

Nice. Thanks for the tip! Fixed via fd16e01487323026a4f3b1d25625f3b1e083c2fb