pug

Foreach loop in jade (node.js template engine)

感情迁移 提交于 2019-11-29 02:17:53
问题 Ok, I am getting an associative array from node server and trying to render it in Jade. I obviously need a foreach loop, but nothing seems to work! I tried these both codes: - foreach row in rows { li= row - } and - rows.forEach(function(item)) { li= item - }) the array I am passing is called "rows". Any idea why this is not working? I am getting this error: 500 SyntaxError: Unexpected identifier and, with the second code: 500 SyntaxError: Unexpected token ) 回答1: try each item in rows li=

how to protect a public dynamic folder in nodejs

自古美人都是妖i 提交于 2019-11-29 01:13:51
问题 i show pictures with jade in public/images/picture.jpg but i want to protect some pictures or restrict the access to the public folder how do that?? project node_modules public images image.jpg javascripts stylesheets protected_folder* image_protected.jpg views 回答1: Note: for all these examples, I'm using an application structured like the following: . ├── app.js └── public ├── protected │ └── file.txt <-- contains text "protected file" └── regular └── file.txt <-- contains text "regular file

Passing variables through Jade templates

安稳与你 提交于 2019-11-28 22:55:37
It's possible in Jade to pass variables from one template to another?. I want to do something like this: tmp1.jade div.anyClass include components/checkbox('someLabel') tmp2.jade div.otherClass div.label {someLabel} Thanks! Included templates inherit the variables scope of the template that included them, so what you're after will happen automatically for you. So the following will work: tmp1.jade - var label = 'value' div.anyClass include tmp2 tmp2.jade div.otherClass div.label #{label} You can also use mixins to pass variables, they are like functions (you define them first, then call them)

Jade templating in Meteor

主宰稳场 提交于 2019-11-28 22:03:06
问题 In the Meteor FAQs http://meteor.com/faq/how-do-i-package-a-new-templating-system there is some information about adding a different (than the default Handlebars) templating system. Jade is the only other example explicitly called out elsewhere in the docs. So is somebody already working on Jade? If not, is it feasible for me to start? Or is it still too early? e.g. : The package API is rapidly changing and isn't documented, so you can't make your own packages just yet. Coming soon. I've been

Is it possible to render x.jade partial in angular?

放肆的年华 提交于 2019-11-28 20:11:39
问题 The following code works if i was rendering some.html instead of some.jade . angular.module('myApp', []). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/', {templateUrl: 'partials/some.jade', controller: myAppController}). otherwise({redirectTo: '/login'}); }]); Is it possible to render a jade file as a partial in angular? 回答1: Yes it is possible. Look at the following link Two important points to note are: templateUrl: 'partials/some' instead of templateUrl:

Using Jade templates in Backbone.js

家住魔仙堡 提交于 2019-11-28 20:07:54
问题 I love the HAML-like syntax of Jade's templating engine in Node.js, and I would love to use it client-side within Backbone.js. I've seen Backbone commonly using Underscore.js templating in the following style. /* Tunes.js */ window.AlbumView = Backbone.View.extend({ initialize: function() { this.template = _.template($('#album-template').html()); }, // ... }); /* Index.html */ <script type="text/template" id="album-template"> <span class="album-title"><%= title %></span> <span class="artist

Integrating Jade in Yeoman's server/watch/reload tasks

六月ゝ 毕业季﹏ 提交于 2019-11-28 19:35:58
I've been playing around with Yeoman & Jade . I've created a small test app via yeoman init angular (it's an angular app, but that's not the point here)... When I enter yeoman server at the command line, it will: compile coffeescript & compass files start a server start a browser watch & reload coffeescript & compass changes in the browser Which is a great feature of Yeoman! Now I want the same feature with Jade. So I installed grunt-jade via npm install grunt-jade and added the following config in GruntFile.js to compile the jade templates: jade: { html: { src: ['app/views/*.jade'], dest:

How to make Jade stop HTML encoding element attributes, and produce a literal string value?

守給你的承諾、 提交于 2019-11-28 19:08:13
UPDATE Jade v0.24.0 fixes this with a != syntax for attributes. option(value!='<%= id %>') I'm trying to build an <option> with jade, where the value of the option is an UnderscoreJS template marker: <%= id %> but I can't get it to work because jade is converting my marker text to <= id > . Here's my Jade markup: script(id="my-template", type="text/template") select(id="type") <% _.each(deviceTypes, function(type){ %> option(value='<%= type.id %>') <%= type.name %> <% }) %> I expect it to produce this html: <script id="my-template" type="text/template"> <select id='type'> <% _.each(deviceTypes

Accessing Express.js req or session from Jade template

一曲冷凌霜 提交于 2019-11-28 18:41:28
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 }); Dominic Barnes 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 3 Just add app.use(express.cookieParser()); app.use(express.session({secret:

Difference between include and block in Jade

最后都变了- 提交于 2019-11-28 18:16:21
What is the the difference between blocks and using include when you are creating Jade templates? When do you use one over the other? A block is a placeholder. Its content comes from another jade file. An include is a placeholder, too. Its content also comes from another jade file. So far, both are equal. But: include embeds a complete file. The including file defines which file is being included. Hence include is fine for outsourcing parts such as a footer or a header, which are always loaded the same way. A block just defines a placeholder in the top file. Which content is included is not