pug

Express middleware passing variable, error 'TypeError: Cannot destructure property' in middleware function but works via route definiton

痴心易碎 提交于 2020-01-25 07:58:30
问题 I am using pug templates in express and have a layout which has my top navigation toolbar etc. Inside this layout (viewable on all routes) I want to include a count of some items in the toolbar (without having to include the request for each pages/route definition ideally). So I thought I should use middleware. I am able to use the response userProfile anywhere on the page in the /user view eg but when I try to add the const {_raw, _json, ...userProfile} = req.user; to the middleware I get

Express middleware passing variable, error 'TypeError: Cannot destructure property' in middleware function but works via route definiton

本小妞迷上赌 提交于 2020-01-25 07:58:11
问题 I am using pug templates in express and have a layout which has my top navigation toolbar etc. Inside this layout (viewable on all routes) I want to include a count of some items in the toolbar (without having to include the request for each pages/route definition ideally). So I thought I should use middleware. I am able to use the response userProfile anywhere on the page in the /user view eg but when I try to add the const {_raw, _json, ...userProfile} = req.user; to the middleware I get

How can I invoke ClientJade through Gulp?

*爱你&永不变心* 提交于 2020-01-25 04:26:09
问题 I have been asked to help set up Gulp in a project using ClientJade to support Jade template usage on the client. Currently there are three folders of templates, and ClientJade is run on each to produce three template JavaScript files which are imported and used at run time. The goal of introducing Gulp is to be able to watch the three template source folders and recompile the appropriate JavaScript files in the build folder when a change occurs. Unfortunately there is no gulp ClientJade

pugjs able to use ternary for text?

冷暖自知 提交于 2020-01-23 20:24:21
问题 I know we are able to use ternary for attr but I am wondering if we can do it with plain text? let's say I have something like this button.btn.btn-round.btn-info | if image | Change Image else | Add Image the button will have the text either Change Image or Add image if image variable exists Is this possible to use ternary? Thanks in advance for any help and suggestions 回答1: Yes, it's absolutely possible. Just use the equals sign at the end of the element definition to get pug to evaluate

JQuery insert cell to specific position of tr value and td value

大城市里の小女人 提交于 2020-01-17 06:46:44
问题 I am having a table contain the following structure: The status in thead having value with unique number, and the date also having a unique value of the date itself. What I want is to add cell after matching the (cell status and cell date), so , I am having the following JSON: { "data": [ [ { "orderStatus": 2, "date_formatted": "15-05-2017", "counter": 2 }, { "orderStatus": 4, "date_formatted": "15-05-2017", "counter": 14 }, { "orderStatus": 5, "date_formatted": "15-05-2017", "counter": 12 },

Why is my Express / Jade app rendering blank pages?

孤街浪徒 提交于 2020-01-17 03:36:08
问题 I just added another Jade template to my express project, and now it renders blank pages, with empty head and body tags. It works when index.jade extends layout.jade, but it breaks if layout.jade extends logo.jade. There are no errors in the console. Here is a simplified version of the project, which works fine. app.js: var express = require('express'), http = require('http'), path = require('path'), request = require('request'); var app = express(); app.configure(function(){ app.set('port',

Parameterised jade includes

蹲街弑〆低调 提交于 2020-01-16 06:20:06
问题 I want to have a mixin like this: mixin foo(name) style include styles/#{name}.css However this syntax is invalid. Is there any way to parameterise a Jade include like this? 回答1: Currently not supported in version 2 probably will be. 来源: https://stackoverflow.com/questions/27881344/parameterised-jade-includes

Re-using function inside jade

你说的曾经没有我的故事 提交于 2020-01-15 10:53:28
问题 I have a inline script and code block repeated 2 times inside a .jade file and would like to: re-use it. (i mean DRY it and have just one block/function) escape the html like suggested here, right now I am using != linkExist('foo') My idea was to use mixin , but don't know how to. My code works as is, but would like to know how to write it better. Thought about codereview (because my code actually works and I just want to improve it) but the jade has not even a tag there yet, so I think SO

Add Active Nav Link Class In Pug

北战南征 提交于 2020-01-14 15:26:13
问题 I am having trouble finding a good solution. The problem is I want a dynamically updated active class on my nav items, however I don't know how to do so. Can anyone help me with a solution for giving the nav item corresponding to the current page a certain class, automatically? This is my layout.pug page: doctype html html(lang="en") head include components/head body(id="page-top" role="document") include components/header main block main include components/footer This is what I currently

Node Express Jade - Checkbox boolean value

时间秒杀一切 提交于 2020-01-14 14:33:31
问题 I'm using Node+Express+Jade to render some webpages. On a form there are 2 checkboxes. When the form is submitted through POST, if the checkbox is checked, I get req.body.checkbox1 -> 'on' , if isn't checked, I get req.body.checkbox1 -> undefined Is possible to get checkbox value as true or false ? Here's my server side test code var bodyParser = require('body-parser'); var express = require('express'); var app = express(); app.use(bodyParser.urlencoded({extended: true})); app.use(express