我使用模板作为基础,并希望它知道在使用它的页面中设置的一些变量...
文件:template.jade
vars = vars || {some:"variables"}
!!! 5
head
title vars.some
Run Code Online (Sandbox Code Playgroud)
文件:page.jade
vars = {some:"things"} //- this does not get used from within template.jade
extends template
Run Code Online (Sandbox Code Playgroud)
我希望编译的page.jade有一个标题"东西"
我想用一个简单的循环for(int i=0; i<10; i++){}.
我如何在Jade引擎中使用它?我正在使用Node.js并使用expressjs框架.
我是新手Node.js,我试图在终端中运行一个项目(由其他开发人员制作)node app.js.但我遇到下面的错误,你知道如何运行这个项目吗?
我在这里遵循了一些指令来运行一个项目.
错误日志如下:
Junryls-Mac-mini:app junrylmaraviles$ node app.js
/Users/junrylmaraviles/Desktop/myfolder/mysubfolder/app/app.js:1
(function (exports, require, module, __filename, __dirname) { define('src/app'
^
ReferenceError: define is not defined
at Object.<anonymous> (/Users/junrylmaraviles/Desktop/myfolder/mysubfolder/app/app.js:1:63)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
Run Code Online (Sandbox Code Playgroud) 我正在使用Jade和Express,我想在include语句中使用变量.例如:
app.js
app.get('/admin', function (req, res) {
var Admin = require('./routes/admin/app').Admin;
res.render(Admin.view, {
title: 'Admin',
page: 'admin'
});
});
Run Code Online (Sandbox Code Playgroud)
layout.jade
- var templates = page + '/templates/'
include templates
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到了错误 EBADF, Bad file descriptor 'templates.jade'
我甚至试过了
include #{templates}
Run Code Online (Sandbox Code Playgroud)
无济于事.
我需要在网页中加入一个javascript文件.我写了以下内容:
include /../scripts/jquery.timeago.js
Run Code Online (Sandbox Code Playgroud)
但我明白了
<script>/*
* timeago: a jQuery plugin, version: 0.8.2 (2010-02-16)
* @requires jQuery v1.2.3 or later
*
* Timeago is a jQuery plugin that makes it easy to support automatically
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
*
* For usage and examples, visit:
* http://timeago.yarp.com/
*
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
*/
(function($) {
....
</script> …Run Code Online (Sandbox Code Playgroud) 我在服务器上有一个非常重量级的查询,导致新的页面呈现,我想将一些查询结果传递给客户端(作为javascript对象数组).这基本上是这样我以后不必再进行单独的JSON查询来获取相同的内容(主要是静态的).这些数据最终会有用,但最初并没有这样,所以我没有直接将其放入文档中.
app.get('/expensiveCall', function(req, res) {
// do expensive call
var data = veryExpensiveFunction();
res.render('expensiveCall.jade', {
locals: {
data: data,
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
data是一个对象数组,最初只使用了一些对象.我想传递整个数据或一些子集(取决于具体情况).我的玉看起来像普通的玉,但我想包括类似的东西
<script type="text/javascript">
var data = #{data};
</script>
Run Code Online (Sandbox Code Playgroud)
但这不起作用(它是一个对象数组).
在Meteor FAQs http://meteor.com/faq/how-do-i-package-a-new-templating-system中,有一些关于添加不同(比默认Handlebars)模板系统的信息.Jade是文档中其他地方明确指出的唯一其他示例.
有人在研究Jade吗?如果没有,我开始可行吗?还是现在还为时尚早?例如:
软件包API正在快速变化,并且没有记录,因此您无法创建自己的软件包.快来了.
在我目前的Ember.js项目中,我一直在努力爱上Handlebars,但对我来说,没有什么比Jade更优雅了.
我是Node.js和Jade的新手,我试图使用#{Date.now()}它,它给了我数字.如何以mm/dd/yy格式显示日期?
我们如何在Jade/Pug中的多行上写一个长属性值?
SVG路径往往很长.我们想在多行上写一个属性值以帮助提高可读性.例如,Mozilla 用HTML编写的教程很容易阅读.
任何改变这个的方法:
h3 Arcs
svg(width="320px", height="320px")
path(d="M10 315 L 110 215 A 30 50 0 0 1 162.55 162.45 L 172.55 152.45 A 30 50 -45 0 1 215.1 109.9 L 315 10",
stroke="black", fill="green",
stroke-width="2", fill-opacity="0.5")
Run Code Online (Sandbox Code Playgroud)
进入这样的事情:
h3 Arcs
svg(width="320px", height="320px")
path(d="M10 315 " +
"L 110 215 " +
"A 30 50 0 0 1 162.55 162.45 " +
"L 172.55 152.45 " +
"A 30 50 -45 0 1 215.1 109.9 " + …Run Code Online (Sandbox Code Playgroud)