pug

How to get the value on url in pug

不打扰是莪最后的温柔 提交于 2020-01-04 02:09:27
问题 I have an url like this: http://localhost/editblog/58a5da1df3ec9614fc9893d3 and code in pug like this: input.form-control(type='hidden', name='id', value='') The question is how to get the value on the url and pass it to value='' I've known about req.params.id but it is not what could solve my issue 回答1: When you render your pug template you could send any variable as res.locals property so it will send to template: app.get('/editblog/:id', function(req, res) { res.render('editblog', { title:

trying to render html files using jade but it still adresses it as a jade

隐身守侯 提交于 2020-01-04 01:58:09
问题 i have read theses two posts regrading my issue: http://stackoverflow.com/questions/4529586/render-basic-html-view-in-node-js-express http://stackoverflow.com/questions/12046421/how-to-configure-express-js-jade-to-process-html-files and my code is as follows: app.engine('.html', require('jade').__express); app.set('views', __dirname + '/app/views'); app.set('view engine', 'html'); it is clear that for some reason it is trying to read index as if it was still a jade file and thus i am getting

Using python code in pyjade

China☆狼群 提交于 2020-01-03 16:51:11
问题 I'm trying to generate a list using pyjade, like so: ul - for i, (label, link) in enumerate(tabs) li(class="selected" if i == selected_index else "") a(href=link)= label But I see this error: UndefinedError: 'enumerate' is undefined I must be embedding python code into Jade wrong. What's the right way to do this? 回答1: Jade uses what I refer to as "implicit enumeration" - it enumerates values in a list simply by adding one more variable, i , than there are values to unpack: for item, i in list

Using python code in pyjade

核能气质少年 提交于 2020-01-03 16:48:21
问题 I'm trying to generate a list using pyjade, like so: ul - for i, (label, link) in enumerate(tabs) li(class="selected" if i == selected_index else "") a(href=link)= label But I see this error: UndefinedError: 'enumerate' is undefined I must be embedding python code into Jade wrong. What's the right way to do this? 回答1: Jade uses what I refer to as "implicit enumeration" - it enumerates values in a list simply by adding one more variable, i , than there are values to unpack: for item, i in list

How to split array dynamically based on single value in JavaScript Node.js

ぐ巨炮叔叔 提交于 2020-01-03 15:34:44
问题 I need to split array dynamically based on single value in JavaScript. I've got an array: var dataStuff = [ { Name: 'Apple', Tag: 'Fruit', Price: '2,5'}, { Name: 'Bike', Tag: 'Sport', Price: '150'}, { Name: 'Kiwi', Tag: 'Fruit', Price: '1,5'}, { Name: 'Knife', Tag: 'Kitchen', Price: '8'}, { Name: 'Fork', Tag: 'Kitchen', Price: '7'} ]; And i expect arrays split by Tag, eg. var Fruit = [ { Name: 'Apple', Tag: 'Fruit', Price: '2,5'}, { Name: 'Kiwi', Tag: 'Fruit', Price: '1,5'} ]; var Sport = [ {

trying to display data in jade from mongodb

我的梦境 提交于 2020-01-03 05:54:13
问题 trying to display data from mongoose schema to jade temaplate but it dosent work no matter what i try , so please help me and thanks . first here is my book schema models/book.js const mongoose = require('mongoose') const schema = mongoose.Schema const BookSchema = new schema({ title: String, author: String, isbn: Number, date: { type: Date, default: Date.now}, description: String }) module.exports = mongoose.model('Book', BookSchema) and here is my controller for the book model const Book =

How to debug print an object from jade

两盒软妹~` 提交于 2020-01-02 03:31:37
问题 How to debug print an object from jade,Like console.log() in javascript 回答1: You can debug with console.log from jade like this: div - console.log(the_object_you_want_to_log) div 回答2: This helped me! Able to see whole tree of Object in console. Start script. from leftmost and just give space or tab according to your template before console.log. script. console.log(!{JSON.stringify(Object)}) 回答3: You can debug like this div = your_debug_data div or formatted style like: code.formattedDebug #

Unable to access req.user with Passport.js and Express 4

南楼画角 提交于 2020-01-02 03:12:06
问题 I've been creating an app with Passport, Express 4 and Jade. I would like to show the user a navbar that changes when they log in. However, I cannot access req.user for any other page than the profile page, which calls isLoggedIn: function isLoggedIn(req, res, next) { // if user is authenticated in the session, carry on if (req.isAuthenticated()) return next() // if they aren't redirect them to the home page res.redirect("/login") } Using any other function to not redirect the user when not

You should not have pug tags with multiple attributes

ぃ、小莉子 提交于 2020-01-01 16:47:39
问题 Pug mixin with computed CSS class name My pug mixin tweet normally just generates this HTML: <div class='col-md-3'></div> I pass tweet the parameter index , which is a zero-based positive number. When index equals tweetData.index (defined elsewhere) I want the generated div to glow, like this: <div class='blueGlow col-md-3'></div> This is my attempt: mixin tweet(index) div.collapse(class= tweetData.index === index ? "blueGlow" : undefined).col-md-3(data-index=index) The error message is: You

gulp generate html file with jade via markdown json

一曲冷凌霜 提交于 2020-01-01 15:33:43
问题 I'm using gulp-markdown-to-json and gulp-jade My aim is to grab data from markdown file which looks like this: --- template: index.jade title: Europa --- This is a test. grab template: index.jade file and pass it along with other variables to jade compiler. So far I've this: gulp.task('docs', function() { return gulp .src('./src/docs/pages/*.md') .pipe(md({ pedantic: true, smartypants: true })) .pipe(jade({ jade: jade, pretty: true })) .pipe(gulp.dest('./dist/docs')); }); I'm missing a step