Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Email template conditional formatting

More
7 years 1 week ago #172512 by terryaulenbach
I'm trying to set up my email notification templates so that certain multiple choice responses will be included if they have been selected. I have a number of possible answers, but don't want blank lines to show if certain answers weren't selected. Here's what I've started with:

<tr>
<td style="vertical-align: top;"><strong>Topics to review:</strong></td>
<td
{INSERTANS:415993X2706X34550A1}<br />
{INSERTANS:415993X2706X34550A2}<br />
{INSERTANS:415993X2706X34550A3}<br />
{INSERTANS:415993X2706X34550A4}<br />
{INSERTANS:415993X2706X34550A5}<br />
{INSERTANS:415993X2706X34550A6}<br />
{INSERTANS:415993X2706X34550A7}<br />
{INSERTANS:415993X2706X34550A8}<br />
{INSERTANS:415993X2706X34550A9}</td>
</tr>

Is there some way to use an if statement so I don't have the extra <br /> tags?

Terry
The topic has been locked.
More
7 years 1 week ago #172526 by tpartner
I don't think you can do it with SGQA values but you could try something like this with Expression Manager variables:

Code:
{if(!is_empty(Q1_SQ001), 'Q1_SQ001: '+Q1_SQ001+'<br />', '')}    
{if(!is_empty(Q1_SQ002), 'Q1_SQ002: '+Q1_SQ002+'<br />', '')}    
{if(!is_empty(Q1_SQ003), 'Q1_SQ003: '+Q1_SQ003+'<br />', '')}    
{if(!is_empty(Q1_SQ004), 'Q1_SQ004: '+Q1_SQ004+'<br />', '')}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 5 days ago #172850 by terryaulenbach
Hey, Tony. This works... kind of. Any time any email templates are touched after the initial save, it stops working again and the code gets rearranged like so:

{if(!is_empty(WCHelp_A1), WCHelp_A1.question+'<br />
', '')} {if(!is_empty(WCHelp_A2), WCHelp_A2.question+'<br />
', '')} {if(!is_empty(WCHelp_A3), WCHelp_A3.question+'<br />
', '')} {if(!is_empty(WCHelp_A4), WCHelp_A4.question+'<br />
', '')} {if(!is_empty(WCHelp_A5), WCHelp_A5.question+'<br />
', '')} {if(!is_empty(WCHelp_A6), WCHelp_A6.question+'<br />
', '')} {if(!is_empty(WCHelp_A7), WCHelp_A7.question+'<br />
', '')} {if(!is_empty(WCHelp_A8), WCHelp_A8.question+'<br />
', '')} {if(!is_empty(WCHelp_A9), WCHelp_A9.question+'<br />
', '')} {if(!is_empty(WCHelp_other), 'Other: '+WCHelp_other.value+'<br />
', '')} {if(!is_empty(LibraryHelp_A1), LibraryHelp_A1.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A2), LibraryHelp_A2.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A3), LibraryHelp_A3.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A4), LibraryHelp_A4.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A5), LibraryHelp_A5.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A6), LibraryHelp_A6.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A7), LibraryHelp_A7.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A8), LibraryHelp_A8.question+'<br />
', '')} {if(!is_empty(LibraryHelp_A9), LibraryHelp_A9.question+'<br />
', '')} {if(!is_empty(LibraryHelp_other), 'Other: '+LibraryHelp_other.value+'<br />
', '')}

This bit of the email ends up looking like this:

if( ! is_empty(WCHelp_A1), WCHelp_A1.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A2), WCHelp_A2.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A3), WCHelp_A3.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A4), WCHelp_A4.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A5), WCHelp_A5.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A6), WCHelp_A6.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A7), WCHelp_A7.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A8), WCHelp_A8.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_A9), WCHelp_A9.question + ' < br / > ', ' ' ) if( ! is_empty(WCHelp_other), 'Other: ' + WCHelp_other.value + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A1), LibraryHelp_A1.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A2), LibraryHelp_A2.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A3), LibraryHelp_A3.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A4), LibraryHelp_A4.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A5), LibraryHelp_A5.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A6), LibraryHelp_A6.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A7), LibraryHelp_A7.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A8), LibraryHelp_A8.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_A9), LibraryHelp_A9.question + ' < br / > ', ' ' ) if( ! is_empty(LibraryHelp_other), 'Other: ' + LibraryHelp_other.value + ' < br / > ', ' ' )
The topic has been locked.
More
7 years 5 days ago #172854 by tpartner
Don't use the HTML editor.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
More
7 years 5 days ago #172862 by terryaulenbach
OK, thanks. But my curiosity needs to be satisfied... what is it about the editor that breaks the code? Is it something that can be fixed in future updates?

Terry
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • New Member
  • New Member
More
7 years 5 days ago #172872 by LouisGac
Replied by LouisGac on topic Email template conditional formatting
In LS4 the text editor will be changed.
The topic has been locked.
More
7 years 5 days ago #172879 by tpartner
Changed to what?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 5 days ago #172884 by jelo

LouisGac wrote: In LS4 the text editor will be changed.

A wiki roadmap page for LS 4 might help. ETA End of 2019. New HTML Editor. What else is already sealed?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
More
7 years 3 days ago #172971 by terryaulenbach
OK, so I did my editing without switching to HTML. Same problem. If I make changes to one template, save, make changes to the other template and save, the first template gets messed up. I suppose I can change both and then change, but I will always have to remember that any time I update ANYTHING in ANY of the email templates, I'll have to go back and re-enter the code for the 2 notification templates and save both at the same time to avoid sending messed up emails. Is there not a better solution?

Terry
The topic has been locked.
More
7 years 3 days ago #172972 by tpartner
Disable the HTML editor before opening the template editing screen. They are all loaded together, just in hidden tabs.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 3 days ago #172978 by terryaulenbach
Sorry, but I can't see where to disable it.

Terry
The topic has been locked.
More
7 years 3 days ago #172979 by holch
www.limesurvey.org/manual/Global_settings#General

Default editor mode:

Default HTML editor mode: Sets the default mode for integrated HTML editor. The valid settings are:
inline (default): Inline replacement of fields by an HTML editor. Slow, but convenient and user-friendly
popup : Adds an icon that opens a popup window with the HTML editor. Faster, but the HTML code is displayed on the form
HTML source : No HTML editor used, just the plain html source


You will want to set the last option "HTML source". This sets it or the whole installation on all users.

You can also set this on your user preferences, but others might still run into the same problem. If you are the only one doing this kind of stuff, then this is probably the way to go:

www.limesurvey.org/manual/First_login_-_...ces#HTML_editor_mode

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The following user(s) said Thank You: tpartner
The topic has been locked.
More
6 years 8 months ago #177548 by Panoramic
Hello, i've been reading this post and i have one question related to it:

In my email templates, can I add the 'text answer' of some question? I explain it:
I'm doing a survey in which i have uploaded to LimeSurvey a matrix with participants (each one with a token) and their responses from a csv file, wich are the responses from last year's survey (we do this once per year). I would like to send them an invitation email with:

{TOKEN:FIRSTNAME} {TOKEN:LASTNAME}

URL + personal password to acces the survey {TOKEN}

-> The response from one of the survey questions. This question stands for their organitzation, it is a free text question that asks them wich institution do they belong to, because there are people doing the survey for several organitzations (one person that belongs to different institutions)

Can I introduce this in the email template without the expression manager? So I can send the mail to all of these participants with their name and surname, their token and the name of their organization.

Thanks,
Eloi.
The topic has been locked.
More
6 years 8 months ago #177564 by holch
Of course yu can. You probably saved this answer under a custom attribute, let's call it ATTRIBUTE_1.

In this case you can call it either via {TOKEN:ATTRIBUTE_1} or {ATTRIBUTE_1}, I am currently not sure which one works in emails. I think in the emails you must not use the "TOKEN:" part (because the information can only come from the token table anyway with emails).

So it is probably {FIRSTNAME} {LASTNAME} and {ATTRIBUTE_1} (or in whatever custom attribute you saved it.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
6 years 8 months ago #177582 by Panoramic
Thank you Holch!

I didn't save this answer as an attribute, it was a question inside the survey; so I've created the attribute 'Organization', i have downloaded the participants file and i filled the 'attribute' column in the csv file. Then i imported it again to Lime. In the template it works perfectly.

Thanks again,
Eloi.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose