I seem to be having issues with leading/trailing spaces in textareas!
If the last user has typed values into a textarea with leading/trailing spaces across multiple lines, they all disappear with exception to one space in the beginning & end.
Example:
If the textbox had the following lines: (quotes present only to help illustrate spaces)
" 3.0"
" 2.2 "
"0.3 "
it would be saved in the backend as
"<textarea id=... > 3.0/n 2.2 /n0.3 </textarea>"
My template (for this part) is fairly straightforward (entire template, not as easy…):
${label} ${textField}
When I load up the values again, I notice getTextField() is properly getting the desired string, quoted earlier… But when I look at the html page it’s showing
" 3.0"
"2.2"
"0.3 "
And of course when “View Sourcing” it doesn’t have the string seen in getTextField()
What I’ve tried:
- Ensure the backend has setWhitespaceStripping(false); set
- Adding the <#ftl strip_whitespace=false>
- Adding the <#nl> on the same line as ${textField}
No matter what I’ve tried, I’m not having luck keeping the spaces after the interpolation.
Any help would be very appreciated!
Maybe you are inside a
<#compress>...</#compress>(or<@compress>...</@compress>) block. Those filter the whole output on runtime and reduce whitespace regardless where it comes from. I recommend not using this directive. It makes the output somewhat smaller, but it has runtime overhead, and can corrupt output in cases like this.FreeMarker interpolations don’t remove whitespace from the inserted value, or change the value in any way. Except, if you are lexically inside an
<#escape ...>....</#escape>, block, that will be automatically applied. But it’s unlikely that you have an escaping expression that corrupts whitespace. But to be sure., you can check if there’s any<#escape ...>in the same template file (no need to check elsewhere, as it’s not a runtime directive).strip_whitespaceand#ntare only removing white-space during parsing (that’s before execution), so they are unrelated.You can also check if the whitespace is still there in the inserted value before inserting like this:
If you find that they were already removed that probably means that they were already removed before the value was put into the data-model. So then if wasn’t FreeMarker.