pug

Using Jade to iterate JSON

南楼画角 提交于 2019-11-27 23:45:19
问题 I am trying to iterate a JSON doc using JADE. my server(running node.js + express) is doing the following on a .get() request, app.get('/search/', function(req,res){ // Parse the query var dbQuery = url.parse(req.url, true).query; var product = dbQuery.product; var category = dbQuery.category; console.log('Searching for: ' + product + ' in ' + category); //Mongo DB setup then query var result; var server = new mongodb.Server('23.23.129.158', 27017, {}); new mongodb.Db('militaryListDB', server

Passing an object with circular references from server to client-side Javascript while retaining circularity

﹥>﹥吖頭↗ 提交于 2019-11-27 23:20:13
I'm trying to pass an object with circular references from node.js server to client-side javascript. Server (node.js): var object = { circular: object } //.... app.get('/', function(req, res){ res.render('index.jade', {object: object}); }); Client-side Jade/Javascript script var object = !{JSON.stringify(object)}; Here I get the error that object contains circular references. Any way to get the object in client-side javascript, with or without circular references? Douglas Crockford has a solution for this that I have successfully used to solve this problem before: Cycle.js instead of just

JADE + EXPRESS: Iterating over object in inline JS code (client-side)?

与世无争的帅哥 提交于 2019-11-27 21:33:18
i want to implement a google map based on its api. i want to add a path based on coordinates to it. therefore i get my coordinates from my model and want to iterate over the object to fille the map with this points. in my jade template i include the api js code like this: script(type='text/javascript') function initialize() { var myLatLng = new google.maps.LatLng(0, -180); var myOptions = { zoom: 3, center: myLatLng, mapTypeId: google.maps.MapTypeId.TERRAIN }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var flightPlanCoordinates = [ - if (typeof(pins) !=

Actual use of Jade template and angularjs

早过忘川 提交于 2019-11-27 20:12:22
I am building a website using nodejs and express. How to make divisions in a page dynamic? Is Jade used for that? if not how to do it?what is angularjs used for? Please help i searched a lot on google and i couldn't get a clarity in the usage of them. Jade creates the html used in the browser on the server-side . The browser executes a request to the web-server, the web-server executes Jade, which will generate the html that will be sent to the browser. This server-side content generation has been very common in the last ~20 years, but it has quite some cons when building rich internet

Is there any way to use multiple view engines with Express + Node.js

走远了吗. 提交于 2019-11-27 19:06:04
Scenario : I had developed some transactional pages using Node.js , Express + Handlebars as view engine and MongoDB . Now the issue is during module integration I got some of the pages which are built on Express + Jade as view engine. Question : How to integrate pages built on Handlebars & some on Jade ? Sergii Add both engines and consolidate.js in your package.json In yourapp.js var engines = require('consolidate'); app.engine('jade', engines.jade); app.engine('handlebars', engines.handlebars); More info here Express 4.0 and up solution (until it changes again) NPM install the engines you

Rendering HTML in variable using Jade

隐身守侯 提交于 2019-11-27 18:56:00
I have some text stored in a variable which contains some HTML. For example, the <b>cat</b> in the hat. However, when I render it in Jade, it shows up with the tags instead of rendering the formatting. How can I fix this? agent-j Code buffered by = is escaped by default for security, however to output unescaped return values you may use != p!= aVarContainingHTML Pug Doc The syntax you need is : !{yourJsVariable} if you use #{yourJsVariable} it shows < >, but with !{} it doesn't. 来源: https://stackoverflow.com/questions/11191421/rendering-html-in-variable-using-jade

how to render json object in jade and loop through results

Deadly 提交于 2019-11-27 18:51:56
When I send a JSON string to a jade file for rending I'm only able to print out the string in it's entirety but not by it's elements. How do I print out specific elements or loop through the JSON string? app.js: var http = require('http'), express = require('express'), net = require('net'); var app = express(); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.logger('dev')); app.use(express.static(__dirname + '/public')); app.get('/', function (req, res) { var json_string = {"action":"date +%s","result":"1367263074"}; res.render('index', { layout :

ExpressJS 3.0 How to pass res.locals to a jade view?

强颜欢笑 提交于 2019-11-27 17:54:01
I want to display a flash message after a user fails to sign in but I just can't get the variables to show up in my Jade views. I have some pieces, I know I have to use this in my app.configure(): app.use (req, res, next) -> res.locals.session = req.session And I'll set what the flash message is after the user POSTS the wrong password: exports.postSession = (req, res) -> users = require '../DB/users' users.authenticate(req.body.login, req.body.password, (user) -> if(user) req.session.user = user res.redirect(req.body.redirect || '/') else req.session.flash = 'Authentication Failure!' res

Passing objects to client in node + express + jade?

放肆的年华 提交于 2019-11-27 17:17:49
I have a pretty heavyweight query on the server that results in a new page render, and I'd like to pass along some of the results of the query to the client (as a javascript array of objects). This is basically so I don't have to do a separate JSON query later to get the same content (which is mostly static). The data will be useful eventually, but not initially so I didn't put it directly into the document. app.get('/expensiveCall', function(req, res) { // do expensive call var data = veryExpensiveFunction(); res.render('expensiveCall.jade', { locals: { data: data, } }); }); }); data is a