{"id":20698814,"url":"https://github.com/rwson/template","last_synced_at":"2026-04-19T08:31:18.701Z","repository":{"id":87105660,"uuid":"66467367","full_name":"rwson/Template","owner":"rwson","description":"轻量级javascript模板引擎","archived":false,"fork":false,"pushed_at":"2017-03-02T01:57:36.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T03:41:52.285Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rwson.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-24T13:42:36.000Z","updated_at":"2016-08-26T08:27:00.000Z","dependencies_parsed_at":"2023-07-04T22:48:44.701Z","dependency_job_id":null,"html_url":"https://github.com/rwson/Template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rwson/Template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2FTemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2FTemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2FTemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2FTemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwson","download_url":"https://codeload.github.com/rwson/Template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2FTemplate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32000179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"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":[],"created_at":"2024-11-17T00:27:00.814Z","updated_at":"2026-04-19T08:31:18.684Z","avatar_url":"https://github.com/rwson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Template\n\njavascript模板引擎\n\n#### 基础指令说明\n\n指令 | 写法 | 意义\n---|---|---\njavascript可执行语句 | \u003c% for(...) %\u003e | 一些流程控制语句(for, if, else...)\n读取数据属性 | \u003c%= item.title %\u003e | 读取当前数据的属性或本身\nHTML转义输出 | \u003c$ item.html $\u003e | 将HTML中的特殊字符转义后并且输出\n\n#### API\n\nweb端:\n\n\t\u003cscript id=\"template\" type=\"javascript/template\"\u003e\n\t\t\u003cul\u003e\n\t\t\t\u003c% for(var i in obj){ %\u003e\n\t\t\t\t\u003cli\u003e\u003c%= obj[i].text %\u003e\u003c/li\u003e\n\t\t\t\u003c% } %\u003e\n\t\t\u003c/ul\u003e\n\t\u003c/script\u003e\n    \u003cscript type=\"text/javascript\" src=\"src/Template.js\"\u003e\u003c/script\u003e\n    \u003cscript type=\"text/javascript\"\u003e\n        window.onload = function() {\n           var tpl = document.querySelector(\"#template\").innerHTML;\n           var compileRes = Template.compile(tpl);\n           var items = [\n                    {\n                        \"text\": \"list1\"\n                    },\n                    {\n                        \"text\": \"list2\"\n                    },\n                    {\n                        \"text\": \"list3\"\n                    }\n               ];\n           document.querySelector(...).innerHTML = Template.render(compiled, items);\n        };\n    \u003c/script\u003e\n    \n或者\n\n    \u003cscript type=\"text/javascript\" src=\"src/Template.js\"\u003e\u003c/script\u003e\n    \u003cscript type=\"text/javascript\"\u003e\n        window.onload = function() {\n           var tpl = \"\u003c% for(var i = 0, len = obj.length; i \u003c len i ++) %\u003e\u003cli\u003e\u003c%= obj[i].text %\u003e\u003c/li\u003e\u003c% } %\u003e\";\n           var compileRes = Template.compile(tpl);\n           var data = [\n                    {\n                        \"text\": \"list1\"\n                    },\n                    {\n                        \"text\": \"list2\"\n                    },\n                    {\n                        \"text\": \"list3\"\n                    }\n               ];\n           document.querySelector(...).innerHTML = Template.render(compiled, data);\n        };\n    \u003c/script\u003e\n    \n大多数模板引擎中是模板编译方法中使用with语句动态修改其内部的this指向，本模板的compile中没有采用这种做法，而是在指定了一个默认参数obj，因此，在编写模板语句时，对数据的读操作务必采用obj.xxx或者obj['xxx']这种形式，防止在运行时报“xxx is not defined”的异常\n    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwson%2Ftemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwson%2Ftemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwson%2Ftemplate/lists"}