My objective is similar to this can you store a line break in a variable? but I need it to be in GAS/JS/HTML.
mesej
is a variable that stores a long string which needs to be displayed as 2 lines of strings in the html email. That string value is in a gsheet cell A14
. The line break is displayed just fine in gsheet when I used \n
in GAS to break a line after symbol :
but it doesn't happen the same in html email.
I have tried with <br>
and %A0
but ended up having that tags appeared in the html email and when I use mesej.split(":").join(":\n")
, I would get a bounced back email from google support indicates that the email is blocked. Please help to correct my code. Thank you.
My GS function:
function breakline(){
var sheet=SpreadsheetApp.openById("THIS_SHEET_ID").getSheetByName("job");
//some operations in subfn A
var msg1="Career Status";
//some operations in subfn B
var msg2="Desperately Seeking";
var msg=msg1+":\n"+msg2;
sheet.getRange(14,1).setValue(msg);
var mesej=sheet.getRange(14,1).getValue();//"Career Status:Desperately Seeking" 2 lines in 1 cell
var sampling=HtmlService.createTemplateFromFile("sample");
sampling.mesej=mesej;
var mymesej = sampling.evaluate().getContent();
MailApp.sendEmail("email@gmail.com","Job Application"," ",{htmlBody:mymesej});
}
My HTML code:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<?=mesej?>
</body>
</html>
` is being "escaped." And you need it to not be escaped. See if any reading here helps for a method to _not_ escape the HTML in your string: https://developers.google.com/apps-script/guides/html/templates – Marc Oct 23 '20 at 17:03
"+msg2;` – Cooper Oct 23 '20 at 17:29
` can remain as it is and it appears as how I wanted and from there I learnt I could even add in other html tags like `` altogether! – dell Oct 24 '20 at 18:34