回答編集履歴

1

HTMLService/HTMLTemplate を使って、変数の埋め込みとHTMLエンコードを丸投げするサンプルを追記

2020/06/15 02:49

投稿

draq
draq

スコア2573

test CHANGED
@@ -55,3 +55,47 @@
55
55
  }
56
56
 
57
57
  ```
58
+
59
+
60
+
61
+ ---
62
+
63
+ (追記)HTMLService/HTMLTemplate を使って、変数の埋め込みとHTMLエンコードを丸投げするサンプルを追記しておきます。
64
+
65
+ ```JavaScript
66
+
67
+ function myFunction2() {
68
+
69
+ const templateBody = `<!DOCTYPE html>
70
+
71
+ <html>
72
+
73
+ <body>
74
+
75
+ こんにちわ<?=company?> <?=lastName?> <?=firstName?>様<br>
76
+
77
+ </body>
78
+
79
+ </html>`;
80
+
81
+
82
+
83
+ const template = HtmlService.createTemplate(templateBody);
84
+
85
+ template.company = "(会社名 & 会社名)";
86
+
87
+ template.firstName = "(名)";
88
+
89
+ template.lastName = "(姓)";
90
+
91
+
92
+
93
+ const htmlBody = template.evaluate().getContent();
94
+
95
+
96
+
97
+ console.log(`htmlBody = ${htmlBody}`);
98
+
99
+ }
100
+
101
+ ```