이 템플릿을 평가하고 HtmlOutput 객체를 반환합니다. 이 HtmlTemplate 객체에 설정된 모든 속성은 평가 시 범위에 포함됩니다. 템플릿의 오류를 디버그하려면 getCode() 메서드를 사용하여 코드를 검사합니다.
// A template which evaluates to whatever is bound to 'foo'.consttemplate=HtmlService.createTemplate('<?= foo ?>');template.foo='Hello World!';Logger.log(template.evaluate().getContent());// will log 'Hello World!'
평가할 수 있는 JavaScript 코드 문자열을 템플릿 파일을 기반으로 생성합니다. 이 메서드는 템플릿 파일을 기반으로 JavaScript 코드 문자열을 생성합니다.
eval(<code>)를 호출하면 모든 삽입된 서버 스크립트를 실행한 후 템플릿의 콘텐츠가 포함된 새 HtmlOutput 객체가 반환됩니다. 생성된 코드는 사람이 읽을 수 있도록 설계되었으므로 템플릿을 디버그해야 하는 경우
Logger.log(<code>)를 호출하여 생성된 내용을 확인할 수 있습니다.
이 코드를 평가하면 현재 범위의 모든 변수가 암시적으로 바인딩됩니다. 일반적으로 명시적 바인딩을 사용하는 evaluate() 메서드를 사용하는 것이 좋습니다.
consttemplate=HtmlService.createTemplate('<b>The time is <?= new Date() ?></b>',);Logger.log(template.getCode());
리턴
String: 평가할 수 있는 템플릿 기반 문자열
getCodeWithComments()
평가할 수 있는 JavaScript 코드 문자열을 생성하며, 코드의 각 줄에는 템플릿의 원래 줄이 주석으로 포함됩니다. 이 메서드는 템플릿 파일을 기반으로 JavaScript 코드 문자열을 생성합니다. eval(<code>)를 호출하면 모든 삽입된 서버 스크립트를 실행한 후 템플릿의 콘텐츠가 포함된 새 HtmlOutput 객체가 반환됩니다. 생성된 코드는 사람이 읽을 수 있도록 설계되었으므로 템플릿을 디버그해야 하는 경우 Logger.log(<code>)를 호출하여 생성된 내용을 확인할 수 있습니다.
이 코드를 평가하면 현재 범위의 모든 변수가 암시적으로 바인딩됩니다. 일반적으로 명시적 바인딩을 사용하는 evaluate() 메서드를 사용하는 것이 좋습니다.
consttemplate=HtmlService.createTemplate('<b>The time is <?= new Date() ?></b>',);Logger.log(template.getCodeWithComments());
리턴
String: 평가할 수 있는 템플릿 기반 문자열
getRawContent()
이 템플릿의 처리되지 않은 콘텐츠를 반환합니다.
consttemplate=HtmlService.createTemplate('<b>The time is <?= new Date() ?></b>',);Logger.log(template.getRawContent());
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003eHtmlTemplate\u003c/code\u003e helps you dynamically build HTML content within Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods like \u003ccode\u003eevaluate()\u003c/code\u003e to render HTML with data, and \u003ccode\u003egetCode()\u003c/code\u003e to generate the underlying JavaScript.\u003c/p\u003e\n"],["\u003cp\u003eYou can use \u003ccode\u003egetRawContent()\u003c/code\u003e to access the original template content and \u003ccode\u003egetCodeWithComments()\u003c/code\u003e for debugging purposes.\u003c/p\u003e\n"],["\u003cp\u003eThe rendered output can be further handled using the \u003ccode\u003eHtmlOutput\u003c/code\u003e object.\u003c/p\u003e\n"]]],[],null,["# Class HtmlTemplate\n\nHtmlTemplate\n\nA template object for dynamically constructing HTML. For more information, see the [guide to templates](/apps-script/guides/html/templates). \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------|-------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [evaluate()](#evaluate()) | [HtmlOutput](/apps-script/reference/html/html-output) | Evaluates this template and returns an [HtmlOutput](/apps-script/reference/html/html-output) object. |\n| [getCode()](#getCode()) | `String` | Generates a string of JavaScript code, based on the template file, that can be evaluated. |\n| [getCodeWithComments()](#getCodeWithComments()) | `String` | Generates a string of JavaScript code that can be evaluated, with each line of the code containing the original line from the template as a comment. |\n| [getRawContent()](#getRawContent()) | `String` | Returns the unprocessed content of this template. |\n\nDetailed documentation\n----------------------\n\n### `evaluate()`\n\nEvaluates this template and returns an [HtmlOutput](/apps-script/reference/html/html-output) object. Any properties set on this\n`Html``Template` object will be in scope when evaluating. To debug errors in a template,\nexamine the code using the [getCode()](#getCode()) method.\n\n```javascript\n// A template which evaluates to whatever is bound to 'foo'.\nconst template = HtmlService.createTemplate('\u003c?= foo ?\u003e');\ntemplate.foo = 'Hello World!';\nLogger.log(template.evaluate().getContent()); // will log 'Hello World!'\n```\n\n#### Return\n\n\n[HtmlOutput](/apps-script/reference/html/html-output) --- an HtmlOutput object\n\n*** ** * ** ***\n\n### `get``Code()`\n\nGenerates a string of JavaScript code, based on the template file, that can be evaluated. This\nmethod produces a string of JavaScript code based on the template file. Calling `\neval(\u003ccode\u003e)` will return a new [HtmlOutput](/apps-script/reference/html/html-output) object with the content of the\ntemplate after running all embedded server scripts. The generated code is intended to be\nhuman-readable, and so if you need to debug a template you can call `\nLogger.log(\u003ccode\u003e)` to see what was produced.\n\nEvaluating this code will implicitly bind in all variables in the current scope. In general,\nit's preferable to use the [evaluate()](#evaluate()) method, which takes explicit bindings.\n\n```javascript\nconst template = HtmlService.createTemplate(\n '\u003cb\u003eThe time is <?= new Date() ?>\u003c/b\u003e',\n);\nLogger.log(template.getCode());\n```\n\n#### Return\n\n\n`String` --- a string based on the template, which can be evaluated\n\n*** ** * ** ***\n\n### `get``Code``With``Comments()`\n\nGenerates a string of JavaScript code that can be evaluated, with each line of the code\ncontaining the original line from the template as a comment. This method produces a string of\nJavaScript code based on the template file. Calling `eval(\u003ccode\u003e)` will return\na new [HtmlOutput](/apps-script/reference/html/html-output) object with the content of the template after running all embedded\nserver scripts. The generated code is intended to be human-readable, and so if you need to\ndebug a template you can call `Logger.log(\u003ccode\u003e)` to see what was produced.\n\nEvaluating this code will implicitly bind in all variables in the current scope. In general,\nit's preferable to use the [evaluate()](#evaluate()) method, which takes explicit bindings.\n\n```javascript\nconst template = HtmlService.createTemplate(\n '\u003cb\u003eThe time is <?= new Date() ?>\u003c/b\u003e',\n);\nLogger.log(template.getCodeWithComments());\n```\n\n#### Return\n\n\n`String` --- an string based on the template, which can be evaluated\n\n*** ** * ** ***\n\n### `get``Raw``Content()`\n\nReturns the unprocessed content of this template.\n\n```javascript\nconst template = HtmlService.createTemplate(\n '\u003cb\u003eThe time is <?= new Date() ?>\u003c/b\u003e',\n);\nLogger.log(template.getRawContent());\n```\n\n#### Return\n\n\n`String` --- the template's raw content"]]