3

I have a Data Extension with some text fields. In the text fields have copy text with newlines.

When I output this copy text when rendering the email I would like to replace the newlines from the Data Extension fields into with <br/>.

Is there any workaround with AMPScript?

2 Answers 2

5

You can use the replace() AMPscript function:

%%[

var @copyText, @copyTextAdj
set @copyText = AttributeValue("copyText")
set @copyTextAdj = replace(replace(@copyText ,char(13),""), char(10),"<br/>")

]%%
Original:%%=v(@copyText)=%%
<br>Adjusted: %%=v(@copyTextAdj)=%%

Reference:

Function Index

3
  • Hello Adam, thanks a lot. But this doesn't work for me. But i solved it with SSJS. Commented Nov 1, 2016 at 13:53
  • Updated my example to replace carriage return and linefeed. Commented Nov 1, 2016 at 13:58
  • thanks Adam. Its working now. And thanks for the hint of overhead processing. Commented Nov 1, 2016 at 14:20
1

I solved that issue with SSJS:


var text = Variable.GetValue("@copytext");
var newtext = text.replace(/[\r\n]/g,"
"); //Set the Variable to be accessible in AMPscript Variable.SetValue("@newcopytext",newtext);
1
  • 1
    There's extra overhead processing with SSJS in an email. AMPScript is a better choice -- if you have the option. Commented Nov 1, 2016 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .