{"id":23159200,"url":"https://github.com/deno-library/template","last_synced_at":"2025-08-18T02:31:02.501Z","repository":{"id":62421481,"uuid":"279004145","full_name":"deno-library/template","owner":"deno-library","description":"Template engine for Deno","archived":false,"fork":false,"pushed_at":"2024-11-18T08:45:10.000Z","size":9,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-13T19:57:10.253Z","etag":null,"topics":["deno","template-engine"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deno-library.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-12T06:14:25.000Z","updated_at":"2025-04-08T19:03:09.000Z","dependencies_parsed_at":"2022-11-01T17:32:20.811Z","dependency_job_id":null,"html_url":"https://github.com/deno-library/template","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/deno-library/template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Ftemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Ftemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Ftemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Ftemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deno-library","download_url":"https://codeload.github.com/deno-library/template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Ftemplate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270933523,"owners_count":24670428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","template-engine"],"created_at":"2024-12-17T22:32:41.281Z","updated_at":"2025-08-18T02:31:02.128Z","avatar_url":"https://github.com/deno-library.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# template\n\n[![JSR Version](https://jsr.io/badges/@deno-library/template)](https://jsr.io/@deno-library/template)\n\nTemplate engine for Deno\n\n## Interface\n```ts\nexport interface ConstructorOptions {\n  open?: string;       // Open tag, default: {{\n  close?: string;      // Closing tag, default: }}\n  isEscape?: boolean;  // Whether to escape the value of parameter data, default: true\n}\n\nclass Template {\n  constructor(options?: ConstructorOptions)\n  \n  render(str: string, data: object): string;\n  compile(str: string): string;\n  renderCompiled(compiled: Function, data: object): string;\n  renderFile(path: string, data: object): string;\n}\n``` \n\n## Usage\n\n### render\n```ts\nimport Template from \"jsr:@deno-library/template\";\n// import Template from \"https://deno.land/x/template@v0.1.0/mod.ts\";\nconst tpl = new Template();\nconst str = tpl.render(\"abc{{name}}{{name2}}def\\n{{fn}}s{{p.arr}}ww\", {\n  name: \"def\",\n  fn: () =\u003e 1,\n  p: { arr: [{ M: \"w\" }, 2, 3] },\n  age: 30,\n});\nassert(\n  str ===\n    \"abcdef{{name2}}def\\n() =\u0026gt; 1s[{\u0026quot;M\u0026quot;:\u0026quot;w\u0026quot;},2,3]ww\",\n);\n```\n\n### compile\nReuse compiled function\n```ts\nimport Template from \"https://deno.land/x/template@v0.1.0/mod.ts\";\nconst tpl = new Template();\nconst compiled = tpl.compile(\"abc{{name}}\");\nconst str1 = tpl.renderCompiled(compiled, { name: \"def\" });\nconst str2 = tpl.renderCompiled(compiled, { name: \"xyz\" });\nassert(str1 === \"abcdef\");\nassert(str2 === \"abcxyz\");\n```\n\n### not escape\n```ts\nimport Template from \"https://deno.land/x/template@v0.1.0/mod.ts\";\nconst tpl = new Template({\n  isEscape: false,\n});\nconst str = \"abc{{name}}{{name2}}def\\n{{fn}}s{{p.arr}}ww\";\nconst result = 'abcdef{{name2}}def\\n() =\u003e 1s[{\"M\":\"w\"},2,3]ww';\nconst data = {\n  name: \"def\",\n  fn: () =\u003e 1,\n  p: { arr: [{ M: \"w\" }, 2, 3] },\n  age: 30,\n};\n// render\nassertEquals(tpl.render(str, data), result);\n\n// renderCompiled\nconst compiled = tpl.compile(str);\nassertEquals(tpl.renderCompiled(compiled, data), result);\n```\n\n### open and close\n```ts\nimport Template from \"https://deno.land/x/template@v0.1.0/mod.ts\";\nconst tpl = new Template({\n  open: \"\u003c%\",\n  close: \"%\u003e\",\n});\n\n// render\nassertEquals(tpl.render(\"abc\u003c%name%\u003e\", { name: \"def\" }), \"abcdef\");\n\n// renderCompiled\nconst compiled = tpl.compile(\"abc\u003c%name%\u003e\");\nconst str = tpl.renderCompiled(compiled, { name: \"def\" });\nassertEquals(str, \"abcdef\");\n```\n\n### renderFile\nCompiled functions are cached\n```ts\nimport Template from \"https://deno.land/x/template@v0.1.0/mod.ts\";\nconst tpl = new Template();\nconst data = { name: \"def\" };\nconst result = tpl.renderFile(\"./index.html\", data);\n```\n\n## Test\n```bash\ndeno test --allow-read\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeno-library%2Ftemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeno-library%2Ftemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeno-library%2Ftemplate/lists"}