teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

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

2020/06/15 02:49

投稿

draq
draq

スコア2577

answer CHANGED
@@ -26,4 +26,26 @@
26
26
  inlineImages: { myImage1: blob },
27
27
  });
28
28
  }
29
+ ```
30
+
31
+ ---
32
+ (追記)HTMLService/HTMLTemplate を使って、変数の埋め込みとHTMLエンコードを丸投げするサンプルを追記しておきます。
33
+ ```JavaScript
34
+ function myFunction2() {
35
+ const templateBody = `<!DOCTYPE html>
36
+ <html>
37
+ <body>
38
+ こんにちわ<?=company?> <?=lastName?> <?=firstName?>様<br>
39
+ </body>
40
+ </html>`;
41
+
42
+ const template = HtmlService.createTemplate(templateBody);
43
+ template.company = "(会社名 & 会社名)";
44
+ template.firstName = "(名)";
45
+ template.lastName = "(姓)";
46
+
47
+ const htmlBody = template.evaluate().getContent();
48
+
49
+ console.log(`htmlBody = ${htmlBody}`);
50
+ }
29
51
  ```