{"id":13621919,"url":"https://github.com/koajs/ejs","last_synced_at":"2025-05-16T18:09:24.529Z","repository":{"id":14419875,"uuid":"17130890","full_name":"koajs/ejs","owner":"koajs","description":"a koa view render middleware, support all feature of ejs","archived":false,"fork":false,"pushed_at":"2023-03-02T16:33:44.000Z","size":84,"stargazers_count":249,"open_issues_count":1,"forks_count":56,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-08T01:33:06.677Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/koajs.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-02-24T09:17:33.000Z","updated_at":"2025-01-11T00:12:22.000Z","dependencies_parsed_at":"2023-01-13T17:56:18.267Z","dependency_job_id":null,"html_url":"https://github.com/koajs/ejs","commit_stats":{"total_commits":80,"total_committers":22,"mean_commits":"3.6363636363636362","dds":0.5,"last_synced_commit":"866f65eb7cc175265c73d7afaf7a579871ef998a"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/ejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582907,"owners_count":22095518,"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-01T21:01:11.980Z","updated_at":"2025-05-16T18:09:24.511Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# @koa/ejs\n\n\u003e Koa ejs view render middleware. support all feature of [ejs](https://github.com/mde/ejs).\n\n[![Build Status](https://secure.travis-ci.org/koajs/ejs.svg)](http://travis-ci.org/koajs/ejs)\n\n[![NPM](https://nodei.co/npm/@koa/ejs.png?downloads=true)](https://nodei.co/npm/@koa/ejs/)\n\n## Usage\n\n### Example\n\n```js\nconst Koa = require(\"koa\");\nconst render = require(\"@koa/ejs\");\nconst path = require(\"path\");\n\nconst app = new Koa();\nrender(app, {\n  root: path.join(__dirname, \"view\"),\n  layout: \"template\",\n  viewExt: \"html\",\n  cache: false,\n  debug: true,\n});\n\napp.use(async function (ctx) {\n  await ctx.render(\"user\");\n});\n\napp.listen(7001);\n```\n\nOr you can checkout the [example](https://github.com/koajs/ejs/tree/master/example).\n\n### Settings\n\n- root: view root directory.\n- fs: file system module with same Node.js fs interface (default `Node.js fs module`).\n- layout: global layout file, default is `layout`, set `false` to disable layout.\n- viewExt: view file extension (default `html`).\n- cache: cache compiled templates (default `true`).\n- debug: debug flag (default `false`).\n- delimiter: character to use with angle brackets for open / close (default `%`).\n- async: When true, EJS will use an async function for rendering. Depends on async/await support in the JS runtime.\n- outputFunctionName: Set to a string (e.g., 'echo' or 'print') for a function to print output inside scriptlet tags.\n\n### Layouts\n\n`@koa/ejs` supports layouts. The default layout file is `layout`. If you want to change default layout file, use `settings.layout`. Also you can specify layout by `options.layout` in `await ctx.render`.\nAlso you can set `layout = false` to disable the layout.\n\n```\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003ekoa ejs\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch3\u003ekoa ejs\u003c/h3\u003e\n    \u003c%- body %\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Include\n\nSupports ejs includes.\n\n```\n\u003cdiv\u003e\n  \u003c%- include ('user.html') -%\u003e\n\u003c/div\u003e\n```\n\n### State\n\nSupport [`ctx.state` in koa](https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxstate).\n\n\n### TypeScript\n\nIf you're project based on TypeScript, we recommend using [`@types/koa-ejs`](https://www.npmjs.com/package/@types/koa-ejs) until we start supporting it in the upcoming releases.\n\n## Licences\n\n[(The MIT License)](LICENSE)\n","funding_links":[],"categories":["JavaScript","Middleware","仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fejs/lists"}