我有layout.jade,它包含#header#main#foot
,而#main
包含#content
和#侧边栏
。如果我执行res.rend(template)
的操作,我的模板主体将转到#1ontent
,
但现在有些页面很特殊,只想继承#header#main#footer
,模板主体应该转到#main
中,我怎么能在expressjs中做到这一点,我的模板引擎是jade。
我有layout.jade,它包含#header#main#foot
,而#main
包含#content
和#侧边栏
。如果我执行res.rend(template)
的操作,我的模板主体将转到#1ontent
,
但现在有些页面很特殊,只想继承#header#main#footer
,模板主体应该转到#main
中,我怎么能在expressjs中做到这一点,我的模板引擎是jade。
Jade允许您替换(默认)、预置或附加块。例如,假设您希望在每个页面上使用的“head”块中有默认脚本,您可以这样做:
html
head
block head
script(src= /vendor/jquery.js )
script(src= /vendor/caustic.js )
body
block content
现在假设你有一个JavaScript游戏的应用程序页面,你想要一些与游戏相关的脚本以及这些默认值,你可以简单地附加块:
extends layout
append head
script(src= /vendor/three.js )
script(src= /game.js )
如果您希望为任何视图都有一个特殊的布局模板,您只需要使用布局的值以及新模板布局的名称和位置来调用反模板渲染。
res.render( page , { layout: mylayout });
这将用mylayout为#页眉、#页脚和其他内容呈现页面布局的内容。
我想我应该查看视图局部并组织你的模板,以便可以交换出将要更改的内部部分。
I am building a web application using NodeJS splitting the application into a back-end to handle database queries with MongoDB and a front end via a node based webserver that uses interactjs with ...
I have a working Express.js-based app running on Node.js. Now, I want to wrap it up with pm2. To do that, I ve defined ecosystem.json: { "apps": [ { "env": {...
I need to read a large JSON file (around 630MB) in Nodejs and insert each object to MongoDB. I ve read the answer here:Parse large JSON file in Nodejs. However, answers there are handling the JSON ...
I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.
I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...
I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...
Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?
In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...