این الگو را ارزیابی می کند و یک شی Html Output را برمی گرداند. هر ویژگی تنظیم شده بر روی این شیء Html Template در هنگام ارزیابی در محدوده است. برای اشکال زدایی خطاها در قالب، کد را با استفاده از متد get Code() بررسی کنید.
// 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!'
رشته ای از کد جاوا اسکریپت را بر اساس فایل الگو تولید می کند که قابل ارزیابی است. این روش یک رشته کد جاوا اسکریپت را بر اساس فایل قالب تولید می کند. فراخوانی eval(<code>) پس از اجرای تمام اسکریپت های سرور تعبیه شده، یک شی Html Output جدید را با محتوای قالب برمی گرداند. در نظر گرفته شده است که کد تولید شده برای انسان قابل خواندن باشد، بنابراین اگر نیاز به اشکال زدایی یک الگو دارید، می توانید با Logger.log(<code>) تماس بگیرید تا ببینید چه چیزی تولید شده است.
ارزیابی این کد به طور ضمنی به همه متغیرهای موجود در محدوده فعلی متصل می شود. به طور کلی، استفاده از متد evaluate() ترجیح داده می شود که اتصالات صریح را انجام می دهد.
consttemplate=HtmlService.createTemplate('<b>The time is <?= new Date() ?></b>',);Logger.log(template.getCode());
بازگشت
String - رشته ای بر اساس الگو، که می تواند ارزیابی شود
get Code With Comments()
رشتهای از کد جاوا اسکریپت را ایجاد میکند که میتواند ارزیابی شود و هر خط کد حاوی خط اصلی از الگو به عنوان نظر باشد. این روش یک رشته کد جاوا اسکریپت را بر اساس فایل قالب تولید می کند. فراخوانی eval(<code>) پس از اجرای تمام اسکریپت های سرور تعبیه شده، یک شی Html Output جدید را با محتوای قالب برمی گرداند. در نظر گرفته شده است که کد تولید شده برای انسان قابل خواندن باشد، بنابراین اگر نیاز به اشکال زدایی یک الگو دارید، می توانید با Logger.log(<code>) تماس بگیرید تا ببینید چه چیزی تولید شده است.
ارزیابی این کد به طور ضمنی به همه متغیرهای موجود در محدوده فعلی متصل می شود. به طور کلی، استفاده از متد evaluate() ترجیح داده می شود که اتصالات صریح را انجام می دهد.
consttemplate=HtmlService.createTemplate('<b>The time is <?= new Date() ?></b>',);Logger.log(template.getCodeWithComments());
بازگشت
String - رشته ای بر اساس الگو، که می تواند ارزیابی شود
get Raw Content()
محتوای پردازش نشده این الگو را برمی گرداند.
consttemplate=HtmlService.createTemplate('<b>The time is <?= new Date() ?></b>',);Logger.log(template.getRawContent());
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-24 بهوقت ساعت هماهنگ جهانی."],[[["\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,["HtmlTemplate\n\nA template object for dynamically constructing HTML. For more information, see the [guide to templates](/apps-script/guides/html/templates). \n\nMethods\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`evaluate()` \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\nReturn\n\n\n[HtmlOutput](/apps-script/reference/html/html-output) --- an HtmlOutput object\n\n*** ** * ** ***\n\n`get``Code()` \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\nReturn\n\n\n`String` --- a string based on the template, which can be evaluated\n\n*** ** * ** ***\n\n`get``Code``With``Comments()` \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\nReturn\n\n\n`String` --- an string based on the template, which can be evaluated\n\n*** ** * ** ***\n\n`get``Raw``Content()` \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\nReturn\n\n\n`String` --- the template's raw content"]]