pug

jade template conditional class nodejs expressjs

跟風遠走 提交于 2019-12-06 01:42:55
I have a jade template file for my header and uses bootstrap markup. Depending on what page the user is on, the navigation bar needs to add class .active to that nav item. What is the best way to do this avoiding long code like this. header.jade if nav=='home' li.active a(href="/") Home else li a(href='/') Home if nav=='about' li.active a(href='/about') About else li a(href='/about') About route router.get('/about', function(req, res) { res.render('about', { nav:'about' }); }); Notice how if there are many more links in the header, it will get much longer. Is there a better method to add class

Passing data from node to jade?

不想你离开。 提交于 2019-12-06 01:32:37
The problem is I render a view and send some data console.log(products); // shows an array res.render('seller/sell',{'shop_id':req.user.shop_id ,'products':products}); and I save the data like this in jade input(id='shop_id',type='hidden',name='shop_id',value='#{shop_id}') input(id='pd',type='hidden',name='pd',value='#{products}') if(products !='') each val , key in products a(href!='home/sell/edit?id=#{val.id} ',class='product') img(class='product_thum',src!='#{ val.product_thum}',alt!='#{ val.product_name}',title!='#{ val.product_name}') p.product_name #{ val.product_name} and then I try to

How to define jade template for using with Backbone

二次信任 提交于 2019-12-05 21:39:42
I need to use template for rendering of each ItemView: var ItemView = Backbone.View.extend({ className: 'item', template: _.template($('#itemTemplate').html()), initialize: function () { } }); So I need to define html template at first: <script id="itemTemplate" type="text/template"> <img src="<%= photo %>" alt="<%= name %>" /> <h1><%= name %><span><%= type %></span></h1> <div><%= address %></div> <dl> <dt>Tel:</dt><dd><%= tel %></dd> <dt>Email:</dt><dd><a href="mailto:<%= email %>"><%= email %></a></dd> </dl> But I use Nodejs Jade Template Engine and I don't understand how shuold I define in

How to execute js with Jade?

心已入冬 提交于 2019-12-05 20:19:08
i was wondering how to execute js before rendering? This fails -#{somejs} // Outputs just the js-code p #{somejs()} // Executes the js-code, but doenst render the html // In EJS I just write. But how can i do this with node? <%- somejs() %> // I try to use express-messasges (https://github.com/visionmedia/express-messages) with Jade instead of ejs The following both work for me: - var test = Math.sqrt(16); div #{test} or div #{Math.sqrt(25)} If possible, would you please post your somejs() ? Are you certain that it is producing a HTML string? To use express-messages with jade use this code in

Jade - Using Block inside script tag

孤街醉人 提交于 2019-12-05 19:48:12
问题 Hi there I'm trying using Jade's blocks and extends for a node.js project, and the ideia is to have something like this: layout.jade: head script $(document).ready(function() { block js_doc_ready //here goes the doc ready }); index.jade: block js_doc_ready alert('hello!'); alert('one more js line code'); alert('end my js doc ready for this view'); This would give me a index.html like this: ... <head> <script type="text/javascript"> $(document).ready(function() { alert('hello!'); alert('one

How do I close the container <div> in a loop?

别说谁变了你拦得住时间么 提交于 2019-12-05 19:35:50
I have a list of products and I want to show an ad in the product feed. I want something like: <div id="container"> <div id="product">Bla..</div> <div id="product">Bla..</div> <div id="product">Bla..</div> </div> <div id="add"> Adsense Stuff </div> <div id="container"> <div id="product">Bla..</div> <div id="product">Bla..</div> <div id="product">Bla..</div> <div id="product">Bla..</div> <div id="product">Bla..</div> </div> In ERB, I would have: <div id="container"> <% productes.each_with_index do |product,index| %> <div id="product"><%= product %></div> <% if index == 2 %> </div> <div id="add"

How do I render partials with jade without express.js?

…衆ロ難τιáo~ 提交于 2019-12-05 17:13:44
问题 Only info I found was this: http://forrst.com/posts/Node_js_Jade_Import_Jade_File-CZW I replicated the suggested folder structure (views/partials) But it didn't work, as soon as I put !=partial('header', {}) !=partial('menu', {}) into index.jade, I get a blank screen, the error message I receive from jade is: ReferenceError: ./views/index.jade:3 1. 'p index' 2. '' 3. '!=partial(\'header', {})' partial is not defined I'd be very grateful for any help ! (I strongly prefer not to use express.js)

Linking to other jade files

大憨熊 提交于 2019-12-05 16:24:45
问题 I'm trying to understand how Express and Jade works. First of all, am I doing it right when I'm using layout.jade as a template file (header, body, footer) and using different files to show information in the body (see examples below)? The code works fine, but i'm unsure if this is the right way to do stuff in Express. If I should keep going with this structure, how can I link to other files (eg.About.jade) internally from for example index.jade, to show that file instead of index.jade?

Compile client-side Jade templates using Gulpjs

限于喜欢 提交于 2019-12-05 15:56:04
I'm trying to compile all my .jade templates into a single js file, I'm using Gulpjs and gulp-jade, gulp-concat.. I can get the single file but the problem is that all the functions rendered there have the same name, they are all called "template". foo.jade: .fooDiv h1 Foo here foo2.jade: .foo2Div h1 Foo2 here Gulp file: gulp.src("templates/**/*.jade") .pipe(jade({client: true})) .pipe(concat("templates.js")) .pipe(gulp.dest("../website/templates")) That would output a file like this: function template(locals) { var buf = []; var jade_mixins = {}; buf.push("<div class=\"fooDiv\"><h1>Foo here<

Button clicks in Jade

大兔子大兔子 提交于 2019-12-05 14:51:55
问题 I'm having difficulty getting a button to execute a javascript function when it is clicked, below is my jade file extends layout block content - var something = function() { - console.log('something') - } button(onclick='#{something()}') Click Where am I going wrong with this? 回答1: With this line: button(onclick='#{something()}') Click you tell Jade that it should paste the content of the function into the value of the onclick attribute. Just reference the function name: button(onclick=