pug

Node.js/jade syntax error: unexpected token ;

巧了我就是萌 提交于 2019-12-21 23:25:20
问题 I'm trying to learn node.js. I'm working through an example in the OReilly book "Building node applications with mongodb and backbone". I'm running into an error, and I haven't been able to work it out. I hunted the error for a while (in my own version of the code). Most similar cases were related to jade parsing comments badly (which I'm not using here). Looks like another possibility is module versions not being compatible with this code or each other, but I'm not prepared to go digging

Convert Jade to EJS

大兔子大兔子 提交于 2019-12-21 21:15:06
问题 Can anyone please help by convert this Jade to EJS? extends layout block content h1. User List ul each user, i in userlist li a(href="mailto:#{user.email}")= user.username 回答1: There is no block but an include logic available in EJS. Split up the "main layout" that way that you can include a header and footer (or whatever suits your needs). The iteration is expressed in plain JavaScript escaped in sequences of <% ... %> . Using <%= ... %> directly outputs the referenced var. Your resulting

Pass variables to jade template from commandline

你说的曾经没有我的故事 提交于 2019-12-21 04:11:13
问题 I'm planning to use jade templates to generate different htmls depending on if it is in development or in production. At this time, I'm not planning to write code in node. Given this, is it possible to invoke jade from commandline and pass variables? If so, how? if, index.jade is !!! 5 html head title my jade template body h1 Hello #{name} I want to invoke it from command line passing value for name. Thank you 回答1: You need to use the option -O / --obj within the Jade CLI. It accepts 2 type

Angularjs: How to include empty option in select when using ng-option

北慕城南 提交于 2019-12-21 03:14:24
问题 How can I add empty option in the beginning when I use ng-option to provide predefined list of options which doesn't include empty one? An example in jade select(ng-model="property.Value", ng-options="item.Value as item.Name for item in property.Choices") 回答1: Just add an option with empty value inside of the select. select(ng-model="property.Value", ng-options="item.Value as item.Name for item in property.Choices") option(value="") Here's an example - http://jsfiddle.net/sseletskyy/uky9m/1/

How to render precompiled Jade (Pug) templates in a Node.js Express app?

▼魔方 西西 提交于 2019-12-21 02:12:41
问题 I have a nodejs app that uses Express and Jade(now Pug). I want to precompile the jade templates for better performance. I have been able to convert the jade to javascript using jade --client to compile all the .jade files to corresponding .js. How do I use these js files in my app? I don't have much experience with nodejs/express, but I think it must require changing the rendering engine? I have read the official documentation that says to use runtime.js but I couldn't find any documentation

How to render precompiled Jade (Pug) templates in a Node.js Express app?

怎甘沉沦 提交于 2019-12-21 02:12:12
问题 I have a nodejs app that uses Express and Jade(now Pug). I want to precompile the jade templates for better performance. I have been able to convert the jade to javascript using jade --client to compile all the .jade files to corresponding .js. How do I use these js files in my app? I don't have much experience with nodejs/express, but I think it must require changing the rendering engine? I have read the official documentation that says to use runtime.js but I couldn't find any documentation

express view cache acting funny

老子叫甜甜 提交于 2019-12-20 18:43:09
问题 I'm running into some funny stuff with the view cache in express/Jade. The controller fetches an article from MongoDB via Mongoose and hands it to the res.render function. However, after running for a couple of minutes Express starts serving the same compiled template for all requests to that route. This even happens to shared .jade includes that are used in various templates. The database is fetching the correct articles and it doesn't matter if I pass some random strings to the template, I

Express Generator Without Jade

两盒软妹~` 提交于 2019-12-20 17:32:40
问题 I am trying to generate an express skeleton, using the express generator. So it would be this: $ npm install express-generator -g However, it adds a bunch of automatic jade files. I was wondering if there was a way to get rid of those jade files and just using html with the express generator Thanks! 回答1: Try running this command in command prompt: express --help It will give you the express generator help : Usage: express [options] [dir] Options: -h, --help output usage information --version

PHP vs Node.js - Is HTML Rendering slower in Node.js with Jade?

你说的曾经没有我的故事 提交于 2019-12-20 14:19:08
问题 Assuming that we have millions of requests per day. Is the HTML processing in Node.js with Jade slower or faster than PHP's render engine? Or doesn't matter because the difference is really small? I'm using Node.js with the Jade template engine, I really like it. But I was always the guy who worried about performance. I started my developer career with PHP, it was fun but now Node seems much much better, so I decided to switch. I use Jade to Render HTML, because node.js alone lacks it(I know

Access current request in Express/Jade view

假装没事ソ 提交于 2019-12-20 10:41:37
问题 I have a layout Jade view that has a menu via unordered list, and I want to set the <li> to be <li class="active">...</li> when the current page is rendered in the browser. I assume I will have to access the current request to determine when to set the attribute on the <li> I can't find any examples of how to do this so hoping someone can help Thanks 回答1: Try this before your call res.render() in your route: res.locals.path = req.path; res.render('/page'); or res.render('/page', { path: req