{"id":13781472,"url":"https://github.com/thinkjs/think-view","last_synced_at":"2025-04-06T17:31:39.829Z","repository":{"id":57377010,"uuid":"81430017","full_name":"thinkjs/think-view","owner":"thinkjs","description":"View for ThinkJS 3.x","archived":false,"fork":false,"pushed_at":"2019-12-23T04:43:45.000Z","size":28,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-22T04:01:51.655Z","etag":null,"topics":["think-extend","thinkjs","view"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/thinkjs.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":"2017-02-09T08:57:12.000Z","updated_at":"2022-07-05T02:45:36.000Z","dependencies_parsed_at":"2022-09-26T16:41:41.111Z","dependency_job_id":null,"html_url":"https://github.com/thinkjs/think-view","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247522338,"owners_count":20952524,"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":["think-extend","thinkjs","view"],"created_at":"2024-08-03T18:01:26.320Z","updated_at":"2025-04-06T17:31:39.539Z","avatar_url":"https://github.com/thinkjs.png","language":"JavaScript","readme":"# think-view\n[![Build Status](https://travis-ci.org/thinkjs/think-view.svg?branch=master)](https://travis-ci.org/thinkjs/think-view)\n[![Coverage Status](https://coveralls.io/repos/github/thinkjs/think-view/badge.svg?branch=master)](https://coveralls.io/github/thinkjs/think-view?branch=master)\n[![npm](https://img.shields.io/npm/v/think-view.svg?style=flat-square)](https://www.npmjs.com/package/think-view)\n\n## Install\n\n```\nnpm install think-view\n```\n\n## How to use\n\nconfig file `src/config/extend.js`:\n\n```js\nconst view = require('think-view');\nmodule.exports = [\n  view\n];\n```\n\nconfig `view` in `src/config/adapter.js`:\n\n```js\nconst nunjucks = require('think-view-nunjucks');\nconst path = require('path');\nexports.view = {\n  type: 'nunjucks',\n  common: {\n    viewPath: path.join(think.ROOT_PATH, 'view'),\n    extname: '.html',\n    sep: '_' //seperator between controller and action\n  },\n  nunjucks: {\n    handle: nunjucks\n  }\n}\n```\n\nthen can use some methods in controller\n\n## methods in controller\n\n### assign\n\nassign variable to view\n\n```js\nmodule.exports = class extends think.Controller {\n  indexAction(){\n    this.assign('title', 'ThinkJS Application');\n    this.assign({ //assign multi variable\n      title: 'thinkjs',\n      name: 'thinkjs doc'\n    })\n  }\n}\n```\n\n### render\n\nrender file\n\n```js\nmodule.exports = class extends think.Controller {\n  async indexAction(){\n    //render file index_index.html\n    const content1 = await this.render();\n    const content2 = await this.render('doc'); //render doc.html\n    const content3 = await this.render('doc', 'ejs'); //change view render type to ejs\n    const content4 = await this.render('doc', {type: 'ejs', xxx: 'yyy'}); //add other properties\n  }\n}\n```\n\n### display\n\ndisplay view file\n\n```js\nmodule.exports = class extends think.Controller {\n  indexAction(){\n    //render file index_index.html\n    return this.display();\n  }\n}\n```\n","funding_links":[],"categories":["Extends"],"sub_categories":["websocket"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-view/lists"}