pug

How do I pass content from a template to a layout in Express?

谁都会走 提交于 2019-12-02 16:25:49
I have a basic Express server: // server.js: var Express = require('express'); app = Express.createServer(); app.configure(function(){ app.set('views', Path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.set('view options'); }); app.get('/', function (request, response) { response.render('welcome', { locals: {some: 'Locals'} }); }); With a basic jade layout: // views/layout.jade: !!! 5 html(lang='en') head title= pageTitle body h1= pageTitle aside(id="sidebar")= sidebarContent #content #{body} And a simple page: # views/welcome.jade: // How do I pass pageTitle and

What are the pros and cons of both Jade and EJS for Node.js templating? [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-02 14:05:34
Jade versus EJS, what are the pros and cons of each and what purposes are each designed for? Are there any other express-compatible template engines that are good and why? Tan Nguyen I used Jade before. The nice thing about Jade is that you have a shorter syntax which means you can type faster. The block in Jade is pretty powerful which can help me a lot when dealing with complex HTML code. On the other hand, it is hard to do some simple stuff in Jade, thing like adding classes into a DIV based on a simple if condition. I need to put something like this - if (isAdmin) div.admin.user - else div

Jquery Autocomplete with Jade/Pug

廉价感情. 提交于 2019-12-02 10:58:59
i need help for this case, about to implement Jquery Autocomplete in Jade/Pug. The result of autocomplete doesnt display in form, although there are now error shown. Actual : No error, but the data when im typing doesnt display as expected. Expect : The data display in form #combine (automatically) when im typing. I use inline code as "very basic" things. Im sure that there are no error showing in inspect of browser, the script at the right path. Javascript (jqplugins/autocomplete) script(src='/demo/jquery.js', type='text/javascript') link(rel='stylesheet', href='/autocomplete.css') script(src

Nodejs shows Error “Cannot GET /test”

大憨熊 提交于 2019-12-02 10:36:19
I am trying to retrieve output on other url / directory in nodejs but it's Display Error ("Cannot GET /test"). Please Suggest me what i have to do to get my output on (" http://localhost:8080/test "). var express = require('express'); var app = express(); var bodyParser = require('body-parser'); var multer = require('multer'); var upload = multer(); var session = require('express-session'); var cookieParser = require('cookie-parser'); app.set('view engine', 'pug'); app.set('views','./views'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(upload.array()

Evaluate custom javascript method (CircularJSON) with Jade

穿精又带淫゛_ 提交于 2019-12-02 07:52:57
I want to parse an object into client-side javascript through Jade. Normally this would work: script var object = JSON.parse(#{JSON.stringify(object)}); but my object is circular and I need to do this script var object = CircularJSON.parse(#{CircularJSON.stringify(object)}); but it throws the error Cannot call method 'stringify' of undefined which I guess is because Jade doesn't recognise my CircularJSON method. Any way to make it? laggingreflex It could be require d and passed in the locals response.render("index.jade", {CircularJSON : require('circular-json')}); Or it could be defined as a

Express.js - Image only renders on one page

若如初见. 提交于 2019-12-02 07:44:52
I'm trying to make an image appear on multiple pages using Pug and Express. But I've been running into some trouble. The image should be rendered on the page on the routes '/', 'data', 'update'. It is successfully rendered on the root '/', but afterwards, disappears from the Sources folder. In app.js I have this middleware about all my route-handlers: app.use(express.static(path.join(__dirname, '/public'))); In the public folder I also have the file styles.css which renders fine on the other pages. I fixed it by putting img(src="/image.jpg") instead of img(src="image.jpg) Anybody know why that

Why am I not able to access the result of multiple networking calls?

故事扮演 提交于 2019-12-02 07:38:27
In my Node app I am trying to get shipment data for packages. I need a way to get the json data and append it to an object or something so that I can pass it to my render page (using pug). This is my code: var test; for(var i = 0; i < result.length; i++) { var currentNumber = result[i].trackingNumber; ups.track(currentNumber, function(err, tracking) { test += tracking }); } res.send(result) It seems that anything I do inside of the ups.track has no scope into the var test, and I can't think of a better way to do this. Any help would be appreciated. First off, ups.track() is an asynchronous

Link to static files from Jade template rendered from a sub route

主宰稳场 提交于 2019-12-02 04:01:45
I have a very basic problem with Node.js/Express/Jade that's surprisingly hard to describe. In my node.js application I use the Express framework for routing of HTTP requests. I also use Jade templates as views, who themselves link to files (css, js etc.) inside a directory that I have declared as static through the app.use(express.static(__dirname + '/public')); command. When I route requests to resources like /about or /contact everything works as expected. But I found that as soon as my resources have multiple 'levels' like so /about/me the same jade view would still render, but it ends up

jade filter :markdown for an object with a

扶醉桌前 提交于 2019-12-02 02:45:50
I have an object from the database with some markdown markup I would like to render with jade. But how? When I apply the :markdown filter I can't use the object as object anymore, but it get's treated as text. I started here: p :markdown entry.content Which renders to plain: entry.content So I tried putting = and - in front or wrapping #{} arround it. Is it possible at all? Filters are compile-time, so if you want to run a markdown filter on a run-time variable, you'll have to render the markdown yourself and pass it to your jade view: https://groups.google.com/forum/?fromgroups=#!topic

Do the indents in an else block continue from the then block?

爷,独闯天下 提交于 2019-12-01 23:47:54
问题 The following Pug script: - data = [ "A", "B", "C", "D" ] - for (i=0,i<data.length;i++) - var even = (i%2)==0 if even .row .col #{data[i]} else .col #{data[i]} produces: <div class="row"> <div class="col">A</div> </div> <div class="col">B</div> <div class="row"> <div class="col">C</div> </div> <div class="col">D</div> What I want is: <div class="row"> <div class="col">A</div> <div class="col">B</div> </div> <div class="row"> <div class="col">C</div> <div class="col">D</div> </div> Why is the