pug

Is it possible to include external files when using Jade’s :markdown filter?

孤者浪人 提交于 2019-12-20 10:35:39
问题 I'm building an Express.js Node app and using Jade templates. Jade provides a :markdown filter which enables embedding Markdown code inside Jade: h1 This is Jade :markdown ## And this is Markdown h3 Back in Jade (Note: In order to use this filter you have to npm install a Markdown engine, e.g. npm install marked --save . You don't have to require() this module within your Express app, but it has to be installed.) So, embedding Markdown within Jade works fine. However, I would like to keep my

How to create an html table with Jade iterating an array

China☆狼群 提交于 2019-12-20 10:26:33
问题 I'm starting with node expressjs framework and I came across this problem I can't solve. I'm trying to display a table with some blog posts (yes, a blog...) but I don't get it done. This is the Jade template code: div table thead tr: th Posts tbody each post, i in userPosts tr(class=(i % 2 == 0) ? 'odd' : 'even'): a(href='/admin/post/' + post.id) #{post.author} - #{post.title} And this is the HTML output: <div> <a href="/admin/post/1">Post 1</a> <a href="/admin/post/2">Post 2</a> <a href="

pugjs(jade) template engine loading css file

一曲冷凌霜 提交于 2019-12-20 09:28:02
问题 I've been searching in the examples on the GitHub but I couldn't find how to load a simple css file into my layout. My first thought was doing something like this link(href="my.css") but it seems it's not working at all. The href points to a correct location online (checked and working) thus maybe I'm forgetting something? 回答1: try: link(rel='stylesheet', href='/stylesheets/style.css') 回答2: I think you need to include the relationship. Try link(rel='stylesheet', href='my.css') 回答3: You need

node.js + jade + express: How can I create a navigation that will set class active if the path matches

僤鯓⒐⒋嵵緔 提交于 2019-12-20 08:47:06
问题 I have come up with the following code but the problem is, there will be duplication of the anchor tag for each menu item.Is there a better way to do this? ul.nav - if(menu="Home") li.active a(href="#") Dashboard else li a(href="#") Dashboard li a(href="#") About li a(href="#") Contact 回答1: This has a little less duplication. ul.nav each name in ["Dashboard", "About", "Contact"] if (menu=="Home") li.active a(href="#")= name else li a(href="#")= name Adding the active class might be better

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

时光总嘲笑我的痴心妄想 提交于 2019-12-20 07:09:24
问题 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

Evaluate custom javascript method (CircularJSON) with Jade

╄→гoц情女王★ 提交于 2019-12-20 05:51:12
问题 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? 回答1: It could be required and passed in the locals response

How to pass a array from node to .js file (pugJs)

China☆狼群 提交于 2019-12-20 04:15:43
问题 I am trying to render a chart (using ChartJS ) as express response. The data points for the chart are stored in node as array. I have to pass it on to the chartJS function. For that I'm currently using express's res.render() method. I have managed to pass the values to .pug file. Now i have to move the data points from .pug file to the .js file/ChartJS function. How do i accomplish this? is this is the correct approach? The end result I expect is that the array values stored in node has to be

jade filter :markdown for an object with a

自闭症网瘾萝莉.ら 提交于 2019-12-20 03:28:14
问题 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? 回答1: Filters are compile-time, so if you want to run a markdown filter on a run-time variable, you'll have to render the

req.files not working node.js - express

走远了吗. 提交于 2019-12-20 02:37:10
问题 Hey so I am trying to accept an uploaded file but everytime I call req.files it is considered undefined... Not sure what I am doing wrong... This is my app.js file: var express = require('express') , user = require('./routes/user') , http = require('http') , path = require('path') , mongoose = require('mongoose') , mongoConnect = mongoose.connect('mongodb://localhost/clothing') , app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(_

req.files not working node.js - express

时光毁灭记忆、已成空白 提交于 2019-12-20 02:37:05
问题 Hey so I am trying to accept an uploaded file but everytime I call req.files it is considered undefined... Not sure what I am doing wrong... This is my app.js file: var express = require('express') , user = require('./routes/user') , http = require('http') , path = require('path') , mongoose = require('mongoose') , mongoConnect = mongoose.connect('mongodb://localhost/clothing') , app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(_