{"id":22965443,"url":"https://github.com/songbug1024/egg-view-twig","last_synced_at":"2025-04-02T04:24:36.443Z","repository":{"id":57220877,"uuid":"87531683","full_name":"songbug1024/egg-view-twig","owner":"songbug1024","description":"egg view plugin for twig.","archived":false,"fork":false,"pushed_at":"2017-04-07T10:02:39.000Z","size":7,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T20:41:24.885Z","etag":null,"topics":["egg-view","eggjs"],"latest_commit_sha":null,"homepage":null,"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/songbug1024.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}},"created_at":"2017-04-07T09:53:46.000Z","updated_at":"2023-03-05T04:26:00.000Z","dependencies_parsed_at":"2022-08-29T04:01:45.395Z","dependency_job_id":null,"html_url":"https://github.com/songbug1024/egg-view-twig","commit_stats":null,"previous_names":["slevp/egg-view-twig"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fegg-view-twig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fegg-view-twig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fegg-view-twig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/songbug1024%2Fegg-view-twig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/songbug1024","download_url":"https://codeload.github.com/songbug1024/egg-view-twig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246754304,"owners_count":20828326,"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":["egg-view","eggjs"],"created_at":"2024-12-14T20:14:41.204Z","updated_at":"2025-04-02T04:24:36.423Z","avatar_url":"https://github.com/songbug1024.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egg-view-twig\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-view-twig.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-view-twig\n[travis-image]: https://img.shields.io/travis/slevp/egg-view-twig.svg?style=flat-square\n[travis-url]: https://travis-ci.org/slevp/egg-view-twig\n[codecov-image]: https://img.shields.io/codecov/c/github/slevp/egg-view-twig.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/slevp/egg-view-twig?branch=master\n[david-image]: https://img.shields.io/david/slevp/egg-view-twig.svg?style=flat-square\n[david-url]: https://david-dm.org/slevp/egg-view-twig\n[snyk-image]: https://snyk.io/test/npm/egg-view-twig/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-view-twig\n[download-image]: https://img.shields.io/npm/dm/egg-view-twig.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-view-twig\n\negg view plugin for [twig].\n\n## Install\n\n```bash\n$ npm i egg-view-twig --save\n```\n\n## Usage\n\n```js\n// {app_root}/config/plugin.js\nexports.twig = {\n  enable: true,\n  package: 'egg-view-twig',\n};\n\n// {app_root}/config/config.default.js\nexports.view = {\n  mapping: {\n    '.twig': 'twig',\n  },\n};\n\n// twig config\nexports.twig = {};\n```\n\nCreate a twig file\n\n```js\n// app/view/hello.twig\nhello {{ data }}\n```\n\nRender it\n\n```js\n// app/controller/render.js\nexports.twig = function* () {\n  yield ctx.render('hello.twig', {\n    data: 'world',\n  });\n};\n```\n\nThe file will be compiled and cached, you can change `config.twig.cache = false` to disable cache, it's disable in local env by default.\n\n### Include\n\nYou can include both relative and absolute file.\n\nRelative file is resolve from current file path.\n\n```html\n// app/view/a.twig include app/view/b.twig\n{% include 'b.twig' %}\n```\n\nAbsolute file is resolve from `app/view`.\n\n```html\n// app/view/home.twig include app/view/partial/menu.twig\n{% include '/partial/menu.twig' %}\n```\n\n### Layout\n\nYou can render a view with layout also:\n\n```html\n// app/view/layout.twig\n\n{% include 'header.twig' %}\n{% block content %}{% endblock %}\n{% include 'footer.twig' %}\n\n// app/view/hello.twig\n\n{% extends 'layout.twig' %}\n{% block content %}\n  Hello {{ data }}, I'm content. \n{% endblock %}\n```\n\n```js\n// app/controller/render.js\nexports.twig = function* () {\n  const locals = {\n    data: 'world',\n  };\n\n  yield ctx.render('hello.twig', locals);\n};\n```\n\n## Configuration\n\nsee [config/config.default.js](config/config.default.js) for more detail.\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/slevp/egg-view-twig/issues).\n\n## License\n\n[MIT](LICENSE)\n\n[twig]: https://github.com/twigjs/twig.js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsongbug1024%2Fegg-view-twig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsongbug1024%2Fegg-view-twig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsongbug1024%2Fegg-view-twig/lists"}