{"id":13668967,"url":"https://github.com/ecomfe/etpl","last_synced_at":"2025-08-02T12:42:42.656Z","repository":{"id":58244011,"uuid":"13731735","full_name":"ecomfe/etpl","owner":"ecomfe","description":"ETPL是一个强复用、灵活、高性能的JavaScript模板引擎，适用于浏览器端或Node环境中视图的生成。","archived":false,"fork":false,"pushed_at":"2017-08-13T13:17:17.000Z","size":1081,"stargazers_count":494,"open_issues_count":11,"forks_count":96,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-20T07:42:43.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://ecomfe.github.io/etpl/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecomfe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-21T03:01:37.000Z","updated_at":"2024-11-19T08:23:29.000Z","dependencies_parsed_at":"2022-08-31T00:31:26.507Z","dependency_job_id":null,"html_url":"https://github.com/ecomfe/etpl","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fetpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fetpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fetpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fetpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomfe","download_url":"https://codeload.github.com/ecomfe/etpl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251077102,"owners_count":21532607,"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","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-08-02T08:00:56.217Z","updated_at":"2025-04-27T01:32:00.161Z","avatar_url":"https://github.com/ecomfe.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# ETPL (Enterprise Template)\n\n[![Build Status](https://travis-ci.org/ecomfe/etpl.svg?branch=master)](https://travis-ci.org/ecomfe/etpl)\n\nETPL是一个强复用、灵活、高性能的JavaScript模板引擎，适用于浏览器端或Node环境中视图的生成。\n\n[WebSite](http://ecomfe.github.io/etpl/)\n\n## Download\n\n除了通过github clone外，你可以通过`右键另存`的方式获得ETpl:\n\n- [压缩代码 (Compressed)](http://s1.bdstatic.com/r/www/cache/ecom/etpl/3-2-0/etpl.js)\n- [源码 (Source)](http://s1.bdstatic.com/r/www/cache/ecom/etpl/3-2-0/etpl.source.js)\n\n也可以通过CDN引用:\n\n```html\n\u003cscript src=\"http://s1.bdstatic.com/r/www/cache/ecom/etpl/3-2-0/etpl.js\"\u003e\u003c/script\u003e\n```\n\n## Start\n\nETpl可以在`CommonJS/AMD`的模块定义环境中使用，也能直接在页面下通过`script`标签引用。\n\n\n### 浏览器环境\n\n直接通过script标签引用，你可以获得一个全局的`etpl`变量\n\n```html\n\u003cscript src=\"etpl.js\"\u003e\u003c/script\u003e\n```\n\n在AMD环境的模块定义时，你可以通过`同步require`获得ETpl模块\n\n```javascript\ndefine(function (require) {\n    var etpl = require('etpl');\n});\n```\n\n在AMD环境，你也可以通过`异步require`获得ETpl模块\n\n```javascript\nrequire([ 'etpl' ], function (etpl) {\n});\n```\n\n*在AMD环境下，请确保你的require.config配置能够让Loader找到ETpl模块*\n\n### Node.JS环境\n\n你可以通过`npm`来安装ETpl\n\n```\n$ npm install etpl\n```\n\n安装完成后，你就可以通过`require`获得一个ETpl模块，正常地使用它\n\n```javascript\nvar etpl = require('etpl');\n```\n\n### 使用\n\n使用ETPL模块，对模板源代码进行编译，会能得到编译后的function\n\n```javascript\nvar render = etpl.compile('Hello ${name}!');\n```\n\n执行这个function，传入数据对象，就能得到模板执行的结果了\n\n```javascript\nvar text = render({ name: 'etpl' });\n```\n\n查看更多例子，或者对模板渲染结果有疑虑，就去ETPL的[example](http://ecomfe.github.io/etpl/example.html)看看吧。\n\n\n## Documents\n\n通过文档，你可以更详细地了解ETpl的语法格式、使用方法、API等内容。\n\n- [模板语法](doc/syntax.md)\n- [API](doc/api.md)\n- [配置参数](doc/config.md)\n\n\n\n## Related\n\n* Sublime Text 语法高亮插件：[sublime-etpl](https://github.com/ecomfe/sublime-etpl)\n* vim 语法高亮插件：[vim-etpl](https://github.com/hushicai/vim-etpl)\n* Atom 语法高亮插件：[atom-etpl](https://github.com/ecomfe/atom-etpl)\n\n\n\n## Compatibility\n\n### ETpl3的新语法\n\n我们认为，当前流行的通过`block`来表达模板继承中的变化，是更好的表达方式。所以在ETpl3中，我们优化了母版的语法，删除了`master`、`contentplacehoder`、`content`标签，引入了`block`标签。\n\n对于ETpl2的使用者，我们提供一个[etpl2to3](https://github.com/ecomfe/etpl2to3)工具，能够帮助你平滑地将ETpl2的模板翻译成ETpl3。\n\n\n### get\n\nETpl2中，为了前向兼容，Engine的`get`方法可以根据target名称获取模板内容。\n\nETpl3不再支持该方法，所有的模板都通过render来使用：\n\n- 直接使用engine实例的render方法 \n- 调用renderer function\n\n如果仍需要该功能，说明你正在维护一个遗留系统，并且没有很频繁的升级需求。请继续使用ETpl2。\n\n\n### merge\n\nETpl的前身是[ER框架](https://github.com/ecomfe/er)自带的简易模板引擎，其基本与前身保持兼容。但出于代码体积和使用频度的考虑，ETpl删除了`merge`API。如果想要该API，请在自己的应用中加入如下代码：\n\n```javascript\n/**\n * 执行模板渲染，并将渲染后的字符串作为innerHTML填充到HTML元素中。\n * 兼容老版本的模板引擎api\n * \n * @param {HTMLElement} element 渲染字符串填充的HTML元素\n * @param {string} name target名称\n * @param {Object=} data 模板数据\n */\netpl.merge = function ( element, name, data ) {\n    if ( element ) {\n        element.innerHTML = this.render( name, data );\n    }\n};\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fetpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomfe%2Fetpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fetpl/lists"}