SAILS.JS EJS 뷰 변경 .EJS 확장 대신 .html 확장을 사용 하시겠습니까?
-
21-12-2019 - |
문제
.html
가 아닌 .ejs
extentions를 사용하도록 SeaLs.js 앱을 구성 할 수 있습니다 (그러나 ejs view engine
를 여전히 사용하십시오)?
sails new app
는 ./views/home/index.ejs
및 ./views/layout.ejs
를 생성합니다.
Extensions를 .html
로 변경하고 싶지만 다른 모든 작업을 동일한 방식으로 유지하십시오.
IE : 이제 ./views/home/index.html
및 ./views/layout.html
를 가질 것이고 홈 페이지는 여전히 정상적인 것으로 레이아웃 페이지에 주입됩니다.
어떻게이 작업을 구성 할 수 있습니까?
해결책
of config/views.js
:
engine: {
ext: 'html',
fn: require('ejs').renderFile
},
.
이 기능에 대한 미래의 지원이 문서에서 제거되기 때문에 보장되지 않으므로주의해서 사용하십시오.
다른 팁
다른 접근법
돛은 기본적으로 EJS 템플릿을 제공합니다.이를 재정의하고 .html 파일을 사용하려면 간단한 솔루션이 있습니다.돛대 앱에서 config / routes.js로 이동하십시오.다음 코드를 볼 수 있습니다
module.exports.routes = {
/***************************************************************************
* *
* Make the view located at `views/homepage.ejs` (or `views/homepage.jade`, *
* etc. depending on your default view engine) your home page. *
* *
* (Alternatively, remove this and add an `index.html` file in your *
* `assets` directory) *
* *
***************************************************************************/
'/': {
view: 'homepage'
}
/***************************************************************************
* *
* Custom routes here... *
* *
* If a request to a URL doesn't match any of the custom routes above, it *
* is matched against Sails route blueprints. See `config/blueprints.js` *
* for configuration options and examples. *
* *
***************************************************************************/
};
.
아래 그림과 같이 '/'로 경로를 제거하십시오.비워 둡니다
새로운 routes.js는
처럼 보입니다.module.exports.routes = {
//Remove '/' :)
};
.
알았어 !!!이제 Sails App에서 HTML 파일을 사용할 수 있습니다.Assets 폴더에 index.html을 넣으십시오.돛은 이제 여기에서 전망을로드합니다 :)
최신 sails.js 0.11, 이것은 또한 유효합니다 :
engine: 'ejs',
extension: 'html',
.
/node_modules/sails/lib/hooks/views/configure.js :
을 확인하십시오.if (typeof sails.config.views.engine === 'string') {
var viewExt = sails.config.views.extension || sails.config.views.engine;
sails.config.views.engine = {
name: sails.config.views.engine,
ext: viewExt
};
}
.