RE: splitting text area string a newline in Advanced PDF Template
I have a custom body transaction field defined as a text area and am trying to add the text of this field into my Advanced PDF Template for my purchase orders. I want to split the text into an array of the lines so that I can print each line in a table row so that longer messages will page-break nicely. With the text value below as an example if I split this using a comma I end up with 3 “lines”:
If the field contains the following value:
“Hi Nick,
How are you today?
Best,
Joe”
<#assign lines = record.custbody_text_message?split(",")> <#list lines as line> ${line_index} </#list>
However; what I am trying to do is split the lines on the “newline” such that I should end up with total of 4 lines. I cannot seem to find a way to get it to work. I have tried all of these variations of arguments with the split function:
<#assign lines = record.custbody_text_message?split("\r\n", "r")> <#assign lines = record.custbody_text_message?split("\r?\n", "r")> <#assign lines = record.custbody_text_message?split("\r?\n+", "r")> <#assign lines = record.custbody_text_message?split("(\r?\n)+", "r")> <#assign lines = record.custbody_text_message?split("\\r\\n", "r")> <#assign lines = record.custbody_text_message?split("\\r?\\n", "r")> <#assign lines = record.custbody_text_message?split("\\r?\\n+", "r")> <#assign lines = record.custbody_text_message?split("(\\r?\\n)+", "r")>
All of the above and many other deviations have failed to produce anything but the entire message as the first and only return value. I’ve read extensively and freemarker.org and the links to oracle relating to splitting strings in java. I can’t figure out what I’m doing wrong. Any help is greatly appreciated!
Hi,
The only other thing I can think is to try some variations of
<br />, <br>, etc.
Thanks,
Chris
Thanks Chris. Yeah I tried those as well thinking maybe they string had already been interpolated by the time I was getting a handle on it in the PDF template but still no luck 🙁
Have you tried it without the second “r” argument?
You know I’ve tried so many things I just decided to go back and retry your suggestions again and the first thing I tried worked! I think prior attempts I was erroneously trying to replace the br tag using regex still.
<#assign lines = record.custbody_text_message?split("<br />")>
Thanks for the help Chris…a good majority of a day of frustration is now behind me!