pug

In Express.js, how can I render a Jade partial-view without a “response” object?

北慕城南 提交于 2019-11-30 12:54:35
问题 Using Express.js, I'd like to render a partial-view from a Jade template to a variable. Usually, you render a partial-view directly to the response object: response.partial('templatePath', {a:1, b:2, c:3}) However, since I'm inside a Socket.io server event, I don't have the "response" object. Is there an elegant way to render a Jade partial-view to a variable without using the response object? 回答1: You can manually compile the Jade template. var jade = require('jade'); var template = require(

Node.js JSON.stringify() causing " in output. Can't parse with Jquery

廉价感情. 提交于 2019-11-30 12:49:49
问题 I am using Node.js (with Express.js) to pass a JSON data object from the server to the client view. When I render the JSON object directly to the view I get the JSON object shown on the page as expected (this WORKS): pageprovider.findAllTag( function(error, pages){ res.send(pages); }) And my output looks like this (much bigger, many nested obj) {"green":{"title":"green","pagesContaining": ""}} When I try to pass it to my Jade View like this: pageprovider.findAllTag( function(error,

Multi-Line Array Literal

瘦欲@ 提交于 2019-11-30 12:48:49
In my Jade template, I'm trying to make an array like so: - var myArray = [ 'one', 'two', 'three' ] But it doesn't compile. Anyone know why? Being able to have a multi-line array that I can use as a mixin argument would make my code much less verbose. - myArray = ['one'] - myArray.push('two') - myArray.push('three') If you wanna. You can use block code: - var myArray = [ "one", "two", "three" ] each row, index in myArray You can't do that :( https://github.com/visionmedia/jade/pull/405 divesario is right is should look like this: - var myArray = [ - 'one', - 'two', - 'three' - ] You can, but

How to include a css file in jade (without linking it)

馋奶兔 提交于 2019-11-30 12:45:10
I have this jade file: !!! 5 html head title test include style(type='text/css') //- DOES NOT WORK! include test.css body //- works include test.css div //- works include test.css The output: $ jade -P test.jade rendered test.html $ cat test.html <!DOCTYPE html> <html> <head> <title>test include</title> <style type="text/css"> //- DOES NOT WORK! include test.css </style> </head> <body>body { color: peachpuff; } <div> body { color: peachpuff; } </div> </body> </html> Of course, I could simply link the css-file, but I do not want to. I didn't test it yet (not on my dev computer ATM) but there is

Jade checkbox checked attribute unchecked based on conditional (if)

谁都会走 提交于 2019-11-30 11:54:27
问题 How do I get jade to render the checked attribute of a checkbox based on a conditional? Like these two versions of the HTML checkbox tag: This seems to be the ONLY valid version of unchecked: > <input type="checkbox" name="vehicle" value="Bike"> While this is checked: > <input type="checkbox" name="vehicle" value="Car" checked="checked"> Here is what I've tried so far: This Jade is fine: input(type="checkbox", name="completed", checked=(true===true ? "checked" : "")).checkbox because it

Node JS Pass a Variable to Jade / Pug

元气小坏坏 提交于 2019-11-30 11:44:09
For some reason I can't pass a variable to the pug template with Node JS. app.get("/", function (req, res) { res.render('index', { hello : 'Hey'} ) }) .... extends layout.pug block content h1 #{hello} guy This just returns "guy" in the index.html file Seetpal singh I think you are using JADE coding (#{hello}) with "pug"(updated jade) plugin with static .html -- completely wrong. follow the lines below: use this first app.set('views', __dirname + '/public/views'); app.set('view engine', 'pug'); than pass this to first visit app.get('/', function (req, res) { res.render('index', { title: 'Hey',

Set page title from a child template in Jade

百般思念 提交于 2019-11-30 11:43:16
I'm wanting to set my page titles in the child templates of the layout via jade. I don't want to set them in the routes since that requires a server restart. Here's what I'm hoping to accomplish: layout.jade: !!! 5 head - var title = title || "Default Title Here" title #{title} // ... child.jade: - var title = "Child Title Here" extends layout // ... Any thoughts on how I can accomplish this would be a great help. Thanks! From https://github.com/visionmedia/jade/issues/654#issuecomment-5859502 layout.jade block variables !!! 5 head - var title = title || "Default Title Here" title #{title}

iterate over an array of objects in jade/pugjs

倾然丶 夕夏残阳落幕 提交于 2019-11-30 11:39:48
I have the following json object: var partners =[{ "name":"partnerx", "image": "imagex" }, { "name": "partnery", "image": "imagey" }] I want to put into a ul object using jade and I tried: ul#slides.swiper-wrapper mixin partners(name, image) li.swiper-slide img(src=#{image} , alt=#{name}) This is not working. tpae Try this: ul#slides.swiper-wrapper each partner in partners li.swiper-slide img(src=partner.image, alt=partner.name) https://pugjs.org/language/iteration.html 来源: https://stackoverflow.com/questions/24316772/iterate-over-an-array-of-objects-in-jade-pugjs

Using !{ } and #{ } interpolation in a jade template (exclamation-object, hash-object)

折月煮酒 提交于 2019-11-30 11:33:56
In a jade template (using express over node.js), I see a template using the following syntax: script(type='text/template', id='data-services') !{data} I don't understand the !{ } construct; apparently it interpolates a javascript object defined elsewhere as: var data={ name:"Doe", age:"21" }; Jade docs & tuts show the use of #{ } for interpolation, but I don't see !{ } . Even #{ } is not documented, so I think it's not jade-specific. Where does this syntax come from and where is it documented? Quite difficult to find it, indeed. Have a look at this resource: http://naltatis.github.io/jade

Submit Jade form

梦想的初衷 提交于 2019-11-30 10:51:34
问题 What is the error with the following Jade form template? I can't get it to submit values. div form(action='/signup',method='post') div(data-role='fieldcontain') fieldset(data-role='controlgroup') label(for='email') email input(id='email',type='text',value='',placeholder='@') div#passworddiv(data-role='fieldcontain') fieldset(data-role='controlgroup label(for='password') password input(id='password',type='password',value='',placeholder='') div(id='hiddendiv',data-role='fieldcontain') fieldset