I have already created a custom alert email handler class which extends DocEmailTemplateHandlerBase in order to define and create custom placeholders for use in Alert emails. This is all working great, but I cannot figure out how to insert a line break in the strings which are being mapped!
For example, I am building a string in a loop, and concatenating data separated by a carriage return/newline using \r\n. But when I view this data in the HTML email, it all comes out as a single line. Any suggestions on how to insert line breaks in my X++ strings so that they are visible in the email which is created? Thanks!
Welcome to the forum and thank you for the question!
You should be able to just use line break tags (<br>) for new lines, but you will have to skip the HTML encoding.
By default the resolved values of the Docentric placeholders are encoded so that special characters are converted into their respective HTML entities (for example, < becomes <), which will mess up the line break tags.
To skip html encoding you just need to add a HTML type parameter to the placeholder by appending the string “?Html” to the end of the name of the placeholder.
For example, let’s say we have a placeholder named TestNewLineLoop and want to add the HTML type parameter to it. We would define it in the email handler class, like so:
public const DocPlaceholderName PlaceholderNewLineLoop = 'TestNewLineLoop?Html';
That’s all that’s needed, now you can insert the placeholder value like you would for any other placholder, like this example from the fillMappingsWithCustomPlaceholderValues() method:
for (int i = 1; i < 11; i++)
testNewLineLoopString += 'Test line #' + int2str(i) + ' ' + '<br>';
Now you can use the placeholder in your email template:
Which should result in an email like this:
Hope this helps!
That worked perfectly, thank you!!