In the body of an email, I want to write a few lines as optional. How do I set the condition to write text only if a variable is filled? Can I create an expression like the one below?
Can anyone help?
I think you should use a variable in your page or an extra POST variable and define its value conditionaly...
So you will just output $_POST.cndtion in your email body (and this value will be empty or include a given value)
before the send mail step, add a setValue and set its value using ternary condition like you do...
For example setValue
cndBody = $_POST.tav_real.length()==0 ? '' : '<b>TAV real (% vol.)' + $_POST.tav_real + '<br>'
(check this value , I didn't pay attention to this...)
Then in your email body just add {{cndBody}}
I think this should work
famousmag is right, but I'm not sure he made clear what your problem was
The problem is you're not correctly performing string interpolation.
'hello {{ $_POST.tav_bruto }}'
is not valid
'hello' + $_POST.tav_bruto
is valid
And there's a possibility of a 2nd problem, we don't know if things like <b>
can be injected with like {{ cndBody }}
inside the e-mail body, it's possible the <b>
may be escaped, so famousmag's solution might not work either for your particular text...
HTML escape is the process of converting special characters to their corresponding HTML entities to prevent them from being interpreted as HTML code.