11

I'm working on a Razor template to add plain text to an outbound email. I notice that if I just add the fields without any logic:

@Fields.Title  
@Fields.Subtitle   

I am able to get line breaks. However if I use logic to check if the fields exist there are no line breaks in the plain text. For example:

@if (Fields.Title != null) { @Fields.Title}  
@if (Fields.Subtitle != null) { @Fields.Subtitle }  

Outputs:

TitleSubtitle

I have tried to use \n and \r\n both inside and out of quotes. How do I add these line breaks?

0
11

Since the @ signifies that you are breaking out of text mode you need to use a text tag to add the line breaks in for plain text.

   @if(Fields.Title != null) {  
   <text>@Fields.Title</text>  
   }  
   @if(Fields.Subtitle != null) {  
   <text>@Fields.Subtitle</text>  
   }  

Outputs:

Title
Subtitle

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.