1

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?

3

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

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

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
    There's extra overhead processing with SSJS in an email. AMPScript is a better choice -- if you have the option. – Adam Spriggs Nov 1 '16 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.