pug

Is it possible to write PHP in jade/pug?

会有一股神秘感。 提交于 2019-12-04 12:17:00
问题 Is it possible? If so, how? If its not, do I have to abandon pug if I need to write PHP in my documents? After searching around I didnt find anyone that has adressed this. 回答1: You can embed PHP in Pug templates the same way you would any literal plain text that you want passed through relatively unmolested[*]. There are a number of options covered in the docs, but I think these are most likely the best options for embedding PHP: After an element, it will just work. For example, p Good

You should not have pug tags with multiple attributes

早过忘川 提交于 2019-12-04 12:01:46
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 should not have pug tags with multiple attributes. The problem is you're trying to define attributes

Partial Not Defined in Jade

谁说胖子不能爱 提交于 2019-12-04 10:58:22
问题 Here is what I have in index.jade. And yes I am using express.js extends layout block content h1 Invoices: != partial("invoice") This matches what I see in every single Jade/Express tutorial. But I get "Reference error: partial not defined". Any ideas why? 回答1: Jade newest version doesn't support partials. You might be following outdated tutorials. Please read up on jade documentation here 回答2: Use include , without quotes (This example is from the jade documentation) users = [{ name: 'Tobi',

Express.js: How can I get the ip Address and render a view?

和自甴很熟 提交于 2019-12-04 10:26:04
I really think this should be easy. But when I render a jade template, I also want to grab the ip address. My code look like this. app.js app.get('/', index.home) index.js exports.home = function(req, res) { res.render('index'); }; Where can I add something like: var ip = req.header('x-forwarded-for') || req.connection.remoteAddress; //or console.log(req.connection.remoteAddress); Just use req.ip and make sure you have app.enable('trust proxy'); if your app is deployed behind a reverse proxy. Express has all the header parsing and proxy logic baked in for you. 来源: https://stackoverflow.com

Preserving newlines in Jade

≡放荡痞女 提交于 2019-12-04 09:54:16
Whenever I render a JADE template, I get all HTML in a single line. This makes it difficult to read in view-source mode. How can I tell JADE to create HTML which is properly indented? Here is my template: #application p#docs a(href='/docs/index.html') Documentation p#user-input input#msg(name='msg', size='50') input#submit(name='submit', type='submit', value='Send a Message') ul#messages jaime In Jade's compiling options set pretty to true. Which can be done in multiple ways depending of how you are compiling them From the command line pass the -P or --pretty flag. From express 3.x: app.locals

how to pass an array of objects to jade template?

主宰稳场 提交于 2019-12-04 09:36:13
i want to pass an array of objects from mongodb to the client... this is the object var objeto_img= { name:'name of the file', image:'image.jpg url', title:'title of the image', caption:'descripcion of the image', link:"#", }; in some profiles the are many images so the is an array of objects like this [var objeto_img= { name:'name of the file', image:'image.jpg url', title:'title of the image', caption:'descripcion of the image', link:"#", },var objeto_img= { name:'name of the file', image:'image.jpg url', title:'title of the image', caption:'descripcion of the image', link:"#", },var objeto

Can I set gulp livereload to run after all files are compiled?

吃可爱长大的小学妹 提交于 2019-12-04 09:21:24
I've got a gulp set up to work with Stylus, Jade and tiny-lr. My problem is that when I save one jade file, it start's compiling them all, therefore live reloading fires on the first file copied to the destination, before the file I am working on currently is compiled, resulting in me having to refresh manually. I have fixing this issue using "gulp-changed" but I don't seem to be able to configure it or something. Anyone had this problem before? I am posting my Gulp file so you can take a look. A timeline diagram of the problem can be found here: https://www.dropbox.com/s/3g37oy25s9mq969/jade

Express + AngularJS + HTML: ng-include not working (404 - Page not found error)

风格不统一 提交于 2019-12-04 09:20:09
I am new to AngularJS . I am trying to use ng-include to include an external HTML page in my main HTML page. But the problem is I am not able to include it and getting 404. Following is the folder structure and the code, Project Folder Structure: buttonClick.jade (This is the starting page.) doctype html html(ng-app) head link(rel='stylesheet', href='/stylesheets/bootstrap.min.css') link(rel='stylesheet', href='/stylesheets/style.css') script(src='/javascripts/angular.min.js') body(class="mainPage") //include footer.html include pageinclude.html pageinclude.html <div> <div>Include Page Demo<

Pass an object to angularjs template from jade

梦想与她 提交于 2019-12-04 08:18:45
I am trying to pass an object from the node to the client like below render: function(req,res){ res.render('auth',{ userData : req.session.user }); } In my auth.jade the code is as below script. var data = !{JSON.stringify(userData)} console.log(data) window.top.location='/profile' So I am redirecting the application to a new route which I have defined in the routeProvider using angularjs app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) { $routeProvider. when('/profile', { templateUrl: 'templates/profile.html', controller: 'ProfileCtrl' }) So is

Equivalent to $.load without jQuery

試著忘記壹切 提交于 2019-12-04 04:57:15
I want to load some Jade content into a certain div on button click. I have found how to do this with jquery, there are several posts on it, and essentially what I want to do is $('#div').load('/somePage'); However, I am unable to use jQuery in my project. Is there an equivalent function in vanilla javascript? I think you can do this with the following; var request = new XMLHttpRequest(); request.open('GET', '/somepage', true); request.onload = function() { if (request.status >= 200 && request.status < 400) { var resp = request.responseText; document.querySelector('#div').innerHTML = resp; } }