pug

Jade conditional (if/else) to add class to div inline

别来无恙 提交于 2019-12-17 22:33:24
问题 Is there a way to do this inline in a jade template? if(typeof fromEdit != 'undefined') div#demo.collapse.in else div#demo.collapse Would like to do this conditional check "inline" and the result would add the .in to the end of the div if fromEdit exists. 回答1: This works: div#demo.collapse(class=typeof fromEdit === "undefined" ? "" : "in") Try it out here. 回答2: If you don't want the class attribute to be added when there is no value, you can assign it undefined instead of an empty string.

Jade: Change active menu item in parent template

不问归期 提交于 2019-12-17 22:32:58
问题 I have a navigation bar in my parent jade template and I'd like to highlight the item which is currently in view. So if I'm on the blog page, ul li Home li.active Blog li Contact Us li About Without copying the navigation bar structure into each child template, is there a way to have the parent template see what page it's extending and apply the active class accordingly? 回答1: parent.jade doctype 5 html block link -var selected = 'home'; //default -var menu = { 'home': '/home', 'blog': '/blog'

Node.js + Express without using Jade

泪湿孤枕 提交于 2019-12-17 22:32:34
问题 Is it possible to use express without any template engine? 回答1: UPDATED Some might have concerns that sendFile only provides client side caching. There are various ways to have server side caching and keeping inline with the OP's question one can send back just text too with send: res.send(cache.get(key)); Below was the original answer from 3+ years ago: For anyone looking for an alternative answer to PavingWays, one can also do: app.get('/', function(req, res) { res.sendFile('path/to/index

Accessing Express.js req or session from Jade template

空扰寡人 提交于 2019-12-17 22:22:37
问题 I am wondering if there is an easy way to access Express.js' req or session variables from within a Jade template without passing it in through the normal response. Or is this the only way? res.render('/', { session: req.session }); 回答1: You'll need to create a dynamicHelper for Express to use. app.dynamicHelpers({ session: function (req, res) { return req.session; } }); Then inside your template, you can use <%= session.logged_in %> or whatever. Note: dynamicHelpers are deprecated in Express

javascript function execution inside jade template

左心房为你撑大大i 提交于 2019-12-17 18:43:10
问题 I am new to nodejs and trying to create a jade file for the html content myfile.jade : Here are the contents of the file: extends layout block content script function capitalize(s) { console.log("Testing js exec"); return s.charAt(0).toUpperCase() + s.slice(1); }; table - each item in list tr td a(href="/collection/#{item.name}") #{capitalize(itemName)} However, when running it throws the following error: Error: mweb/views/collections.jade:8 6| script 7| function capitalize(s) { > 8| console

Error: Failed to lookup view in Express

天涯浪子 提交于 2019-12-17 17:54:17
问题 Note : my auto answer at end of the post I'm trying to make a better experience of nodeJS and i don't really like to get all the script in one file. so, following a post here i use this structure ./ config/ enviroment.js routes.js public/ css/ styles.css images views index index.jade section index.jade layout.jade app.js My files are right now: app.js var express = require('express'); var app = module.exports = express.createServer(); require('./config/enviroment.js')(app, express); require('

Node.js with Express: Importing client-side javascript using script tags in Jade views?

▼魔方 西西 提交于 2019-12-17 17:34:43
问题 I've got a node.js express server running with the Jade template engine. I've got a layout jade file which imports the body of individual views like so: !!! html head title= title || 'Title not set.' body #header h1 Header. #content!= body //- this renders the body of an individual view #footer p Footer. For example, the following index page: p Welcome to the front page. p This page serves as a now.js test. This works fine. However, I now want to include two client-side javascript libraries

How can I get Express to output nicely formatted HTML?

戏子无情 提交于 2019-12-17 05:25:05
问题 When using Express for Node.js, I noticed that it outputs the HTML code without any newline characters or tabs. Though it may be more efficient to download, it's not very readable during development. How can I get Express to output nicely formatted HTML? 回答1: In your main app.js or what is in it's place: Express 4.x if (app.get('env') === 'development') { app.locals.pretty = true; } Express 3.x app.configure('development', function(){ app.use(express.errorHandler()); app.locals.pretty = true;

How can I get Express to output nicely formatted HTML?

£可爱£侵袭症+ 提交于 2019-12-17 05:25:03
问题 When using Express for Node.js, I noticed that it outputs the HTML code without any newline characters or tabs. Though it may be more efficient to download, it's not very readable during development. How can I get Express to output nicely formatted HTML? 回答1: In your main app.js or what is in it's place: Express 4.x if (app.get('env') === 'development') { app.locals.pretty = true; } Express 3.x app.configure('development', function(){ app.use(express.errorHandler()); app.locals.pretty = true;

ENOENT: no such file or directory - error in pug

百般思念 提交于 2019-12-14 03:19:11
问题 When uploaded to Heroku, it is throwing me this error, while no error when running at localhost. Here is browser message: Here is my display.pug extends ../LoginLayout/LoginLayout.pug block content - var createdAt = requser.local.profile.createdAt script(type="text/javascript"). $(document).ready(function() { var createdAt = Date.parse('!{createdAt}'); //- console.log(createdAt); $('.memberSince')[0].innerHTML = moment(createdAt).fromNow(true); }); .parallax-container.display .parallax img