如何在没有express.js的情况下使用jade渲染部分内容?
我发现的唯一信息是:
http://forrst.com/posts/Node_js_Jade_Import_Jade_File-CZW
I复制了建议的文件夹结构(视图/部分)但它不起作用,当我放入
!=partial('header', {})
!=partial('menu', {})
index.jade时,我得到一个空白屏幕,我从jade收到的错误消息是:
参考错误:./views/index.jade:3 1. 'p 索引'
2. ''
3. '!=partial(\'header', {})'部分未定义
我将非常感谢任何帮助! (我强烈不想使用express.js)
Only info I found was this:
http://forrst.com/posts/Node_js_Jade_Import_Jade_File-CZW
I replicated the suggested folder structure (views/partials) But it didn't work, as soon as I put
!=partial('header', {})
!=partial('menu', {})
into index.jade, I get a blank screen, the error message I receive from jade is:
ReferenceError: ./views/index.jade:3
1. 'p index'
2. ''
3. '!=partial(\'header', {})'partial is not defined
I'd be very grateful for any help ! (I strongly prefer not to use express.js)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Jade 有一个名为 include 的命令。只需使用
假定部分的文件名是 *_form.jade*,并且位于同一目录中
Jade has a command called include. Just use
given that the filename of the partial is *_form.jade*, and is in the same directory
截至 2012 年 8 月(可能更早),部分内容已从 Express 中删除。
现在很多教程都已经过时了。看来您可以使用 include 复制大部分部分功能。
例如。
电影.玉
电影.
玉 HTH
As of August 2012 (possibly earlier) Partials have been removed from Express.
A lot of tutorials are now out of date. It seems that you can replicate much of the partial functionality with include.
Eg.
movies.jade
movie.jade
HTH
使用最新的node/express,我得到以下movies.jade模板来调用partials:
其中在views目录中我有movie.jade和movies.jade。
movie.jade 从 app.js 调用:
res.render('movies', { movie: [{ title: 'Jaws' }, { title: 'Un Chien Andalou' }] });
With the latest node/express I get the following movies.jade template to call partials:
where I have movie.jade in the views directory alongside movies.jade.
movies.jade is called from app.js with:
res.render('movies', { movies: [{ title: 'Jaws' }, { title: 'Un Chien Andalou' }] });
我认为部分渲染是在 Express 中完成的,因此您必须获取该代码或编写自己的代码。
我有自己的用于玉石渲染的辅助类,您可以使用它或从 此处 获取一些想法,(它使用 Joose 和 仙人掌)
I think partial rendering is done in express, so you will have to snag that code or write your own.
I have my own helper class for jade rendering with partials that you can use or get some ideas from here, (it's using Joose and Cactus)