pug

How to get a Hexo-built site variables in a pug template?

扶醉桌前 提交于 2019-12-11 16:15:51
问题 I have a Pug template (for what will become the root index.html ) which is supposed to just list the titles of my posts: p first line of the page ul each post in site.posts li= post.title p last line of the page When building the site I get in index.html <p>first line of the page</p> <ul> <li></li> <li></li> </ul> <p>last line of the page</p> I have two posts on this site and the two <li></li> suggest that I iterate over the right variable (and that the variable is known). How can I get the

Routing with parameters in jade from one page to another

淺唱寂寞╮ 提交于 2019-12-11 15:25:54
问题 As i am new to nodejs and express, i would need some help here which could solve my problem. I have table(jade) on the page track.jade which contains information, with "ID" linking to another page. Successfully i can route to another page. But i need to pass the parameters from the table "track.jade" to another page within the table. How can i achieve this? as i am not able find any article which could determine this issue. mixin session(AWB_NO, Product_Name, PCS, Weight, Gross_Weight, DOP,

Connect flash not displaying messages in Pug

笑着哭i 提交于 2019-12-11 15:14:38
问题 I have an application with several routes, and I want to send flash messages of different kinds given the user interaction: either a success or failure message, or in some cases no message. Right now the messages are not displaying and I can't figure out how to get it to work. I'm using Node, Express and Pug. I have a server.js file, routes.js file, message.pug file, and layout.pug file. Here are my files: server.js // init project const express = require('express'); const app = express();

render javascript function return with links inside

。_饼干妹妹 提交于 2019-12-11 13:49:44
问题 I am using this code in a .jade file, inside a for loop to iterate and render html with a object's values: - var linkExist = function(i){ - if (result[i]){ - var html = ',follow on ' + i + ': <a href="' + result[i] + '" target="_blank">' + result[i].split("http://")[1] + '</a>'; - return html; - }; - } #{linkExist('Twitter')} #{linkExist('GitHub')} It adds extra comments and renders a extra < before na d a > after, like < ,follow on Twitter: <a href="http://twitter.com/user" target="_blank"

Jade.escape is undefined on compiled Jade template

☆樱花仙子☆ 提交于 2019-12-11 13:39:07
问题 I've compiled a jade template like: jade --client --no-debug ... Then on client side included jade.js and the compiled template file. But jade.escape is undefined. I notice the compiled template function looks like: function anonymous(locals, attrs, escape, rethrow, merge) { attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge; var buf = []; with (locals || {}) { var interp; buf.push('<h1>'); var __val__ = title buf.push

How to check if user has logged-in for the first time?

烂漫一生 提交于 2019-12-11 13:18:40
问题 I am using Node, Express, and MongoDB for my application. I am rendering Pug Template on server side and using Json Web Tokens for login. I want to display a specific page when user logs in for the first time. Confused how to render it only one time. Maybe adding a field like "accountStatus" and setting status to Active or Inactive will help? 回答1: Save a last_login_time field on DB, it can also be used later for other logic in your app. If the field is empty (or not exist) display the

How to correctly output variables in Jade templating engine?

匆匆过客 提交于 2019-12-11 12:54:43
问题 I was using links like a(href="#{settings.url}") but someone told me that i could just do a(href=settings.url) , which is a better solution (although I do not understand the difference). But now i have a question for another use case. Which one should i use, If any? And Why? link(rel="stylesheet", href="#{settings.url}/assets/css/main.css") link(rel="stylesheet", href=settings.url + "/assets/css/main.css") 回答1: I would say there is not a very important difference, but let's take a look behind

How do I force close a tag in jade templates?

放肆的年华 提交于 2019-12-11 12:39:56
问题 How do you force close a tag in jade? This may be a be a bad example, but If i wanted to put a div in between the </head> & <body> 回答1: Just write HTML in your jade doctype html html(lang="en") <head></head> body jade again But you cannot put jade into your head elements, so when you start using HTML you cannot mix its content and children with jade. 回答2: If you wanted to put something like <div class="your-content"></div> between the body and head , you don't need to resort to plain html.

how to get complex json object and render it in views in node js?

徘徊边缘 提交于 2019-12-11 12:19:21
问题 I have following json with arrays in it In server I'm sending json like this getTrips: function getTrips(req, res, next){ var url = '/CTB-WS/rest/trips?from='+ req.tripinfo.fromCityId + '&to=' + req.tripinfo.toCityId + '&depart-date=' + req.tripinfo.departDate+ '&pax=1'; console.log(url); rest.get(url).on('complete', function(trips) { if (trips instanceof Error) { console.log('Error:', trips.message); } else { console.log('trips'+ JSON.stringify(trips)); console.log('onward trips'+ JSON

How to have a dynamic value in an HTML comment in Jade?

半腔热情 提交于 2019-12-11 11:21:55
问题 I want to programatically set the content of a comment. But this doesn't work: p Hello // = 'Generated at ' + date It just outputs this: <p>Hello</p> <!-- = 'Generated at ' + date --> How can I output a comment with something dynamic in it? I can't see anything in the docs about this. 回答1: Unfortunately for you in this case, Jade does not evaluate the comment's value. You can hack around this by doing: !='<!-- Generated at ' + date + '-->' 来源: https://stackoverflow.com/questions/23829920/how