jade
Jade - robust, elegant, feature rich template engine for Node.js
Jade - Template Engine
I'm trying to author a few paragraphs with Jade, but finding it difficult when there are links inside a paragraph.
The best I can come up with, and I'm wondering if there's a way to do it with less markup:
p
span.
this is the start
of the para.
a(rel='nofollow' href="http://example.com") a link
span.
and this is the rest of
the paragraph.
Source: (StackOverflow)
I'm currently using jade on a new project. I want to render a page and check if a variable available.
app.js
app.get('/register', function(req, res){
res.render('register', {
locals: {
title: 'Register',
text: 'Register as a user.',
}
});
});
register.jade
- if (username)
p= username
- else
p No Username!
I allways get the following error:
username is not defined
Any solutions?
Source: (StackOverflow)
How to I get rid of Jade while using Express with Node.JS? I want to just use plain html. In other articles I have seen that people recommended app.register() which is now deprecated in the latest version.
Source: (StackOverflow)
I have started working with NodeJs. First, I was just using it for providing simple REST api which has access to NOSQL databases. Now I also want to build html pages and use NodeJS to serve static files, as well as dynamic content using ExpressJs. Jade seems to be the templating library on ExpressJs so planning to use it. Are there any good resources so that I can learn jade. Also is it easy to write some big html pages using jade? I'd prefer some thing like php script tags etc embeded in html files as it is more convenient.
Please let me know what you think about it and any alternatives I should look into.
Thanks
Source: (StackOverflow)
I just started using Sublime Text 2 on Mac. I also just started using Jade for my views in Node.js, and am wondering if there is a way to add syntax highlighting for Jade into Sublime Text 2.
Source: (StackOverflow)
I'm trying to get JavaScript to render on my page using Jade (http://jade-lang.com/)
My project is in NodeJS with Express, eveything is working correctly until I want to write some inline JavaScript in the head. Even taking the examples from the Jade docs I can't get it to work what am I missing?
Jade template
!!! 5
html(lang="en")
head
title "Test"
script(type='text/javascript')
if (10 == 10) {
alert("working")
}
body
Resulting rendered HTML in browser
<!DOCTYPE html>
<html lang="en">
<head>
<title>"Test"</title>
<script type="text/javascript">
<if>(10 == 10) {<alert working></alert></if>}
</script>
</head>
<body>
</body>
</html>
Somethings definitely a miss here any ideas?
Source: (StackOverflow)
I've noticed that while using ExpressJS for Node.js, it outputs the html code without any newline characters or tabs. It's not very pretty, although it could technically be more efficient for downloading.
How could I get it to print nice formatted html?
Source: (StackOverflow)
I tried making comments in Jade, but the comments render as text in the HTML. This is my code:
!!! 5
html(lang='en')
body
/ This should be a comment
What am I doing something stupid?
Source: (StackOverflow)
I am using a template as a base, and want it to be aware of some variables set in the page that is using it...
File: template.jade
vars = vars || {some:"variables"}
!!! 5
head
title vars.some
File: page.jade
vars = {some:"things"} //- this does not get used from within template.jade
extends template
I want the compiled page.jade to have a title "things"
Source: (StackOverflow)
I have an express app, storing data in mongo, using Jade as the view engine. I have a simple route that gets the docs in a particular collection, each doc corresponding to a product. The image is base64 encoded. When I try and render as an image though it doesn't work
My route is
exports.index = function(req, res){
mongo.getProducts(function(data) {
res.render('consumer/index', {user: req.session.user, products: data});
});
};
The function that calls is
exports.getProducts = function(callback) {
Product.find().exec(function(err, products){
return callback(products);
});
};
and then my Jade file has the following code
each val in products
img(src="data:image/png;base64,'+#{val.image.data}+'", alt='Image', style="width: 20px; height: 20px")
Looking at the doc directly in Mongo (via robomongo) I get this
I don't know what I'm missing, because in another file I use jQuery datatables to show the documents, and the same approach there correctly renders the image, here is a snippet of the datatables code
"aoColumns": [
{"mData": "name"},
{"mData": "price"},
{"mData": "category"},
{"mData": "description"},
{"mData": "image.data", "mRender": function ( data, type, full ) {
return '<img src="data:image/png;base64,'+data+'", style="width: 20px; height: 20px"></>'}},
{"mData": "promoted"},
{"mData": null}
]
Source: (StackOverflow)
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-name"><%= artist %></span>
<ol class="tracks">
<% _.each(tracks, function(track) { %>
<li><%= track.title %></li>
<% }); %>
</ol>
</script>
What I'd like to see is a way to use AJAX (or some other method) to fetch Jade templates and render them within the current HTML.
Source: (StackOverflow)
I need to include a javascript file to webpage. I write the following:
include /../scripts/jquery.timeago.js
but I get
<script>/*
* timeago: a jQuery plugin, version: 0.8.2 (2010-02-16)
* @requires jQuery v1.2.3 or later
*
* Timeago is a jQuery plugin that makes it easy to support automatically
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
*
* For usage and examples, visit:
* http://timeago.yarp.com/
*
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
*/
(function($) {
....
</script>
as result. But I need:
<script src="/Scripts/jquery.timeago.js" type="text/javascript"></script>
How to do it?
Source: (StackOverflow)
I've been searching in the examples on the GitHub but I couldn't find how to load a simple css file into my layout. My first thought was doing something like this link(rel='nofollow' href="my.css")
but it seems it's not working at all. The href points to a correct location online (checked and working) thus maybe I'm forgetting something?
Source: (StackOverflow)
In jade, I want to put in a html tag conditional as per this method, which puts in
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
at the top of a html file.
I tried
//[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]
//[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]
//[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]
//[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]
head
...
but jade ignores the html tag, and doesn't write in the end </html>
tag. This is invalid html, and results in IE not displaying anything at all.
Is there any way of doing it?
I'm thinking I'll just use a javascript solution if there isn't a way.
Source: (StackOverflow)