Jade conditional (if/else) to add class to div inline
This works: div#demo.collapse(class=typeof fromEdit === “undefined” ? “” : “in”) Try it out here.
This works: div#demo.collapse(class=typeof fromEdit === “undefined” ? “” : “in”) Try it out here.
This should work: – if (typeof(username) !== ‘undefined’){ //-do something -}
Assuming I have node and npm properly installed on the machine, I would Download the code Navigate to inside the project folder on terminal, where I would hopefully see a package.json file Do an npm install for installing all the project dependencies Do an npm install -g nodemon for installing all the project dependencies Then … Read more
You can do it this way: Install ejs: npm install ejs Set your template engine in app.js as ejs // app.js app.engine(‘html’, require(‘ejs’).renderFile); app.set(‘view engine’, ‘html’); Now in your route file you can assign template variables // ./routes/index.js exports.index = function(req, res){ res.render(‘index’, { title: ‘ejs’ });}; Then you can create your html view in … Read more
I used Jade before. The nice thing about Jade is that you have a shorter syntax which means you can type faster. The block in Jade is pretty powerful which can help me a lot when dealing with complex HTML code. On the other hand, it is hard to do some simple stuff in Jade, … Read more
I use Jade to generate templates consumed by AngularJS because I hate writing plain HTML. It looks something like: .control-group( ng-form name=”emailGroup” ng-class=”{“ng-error”: emailGroup.$invalid}” ) label.control-label Email .controls input( type=”email” ng-model=”user.email” required placeholder=”you@example.com” focus-on=’focusEmail’ ) … which I think is a lot cleaner than plain HTML.
As of jade 1.0 there’s an easier way to deal with this, unfortunately I can’t find it anywhere in the official documentation. You can add inline elements with the following syntax: #[a.someClass A Link!] So, an example without going into multiple lines in a p, would be something like: p: #[span this is the start … Read more
It’s a little late but… script. loginName=”#{login}”; This is working fine in my script. In Express, I am doing this: exports.index = function(req, res){ res.render( ‘index’, { layout:false, login: req.session.login } ); }; I guess the latest jade is different? Merc. edit: added “.” after script to prevent Jade warning.
Hide the input with css, add a label and assign it to input button. label will be clickable and when clicked, it will fire up the file dialog. <input type=”file” id=”files” class=”hidden”/> <label for=”files”>Select file</label> Then style the label as a button if you want.
If you have git installed, this worked perfectly for me: cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages git clone https://github.com/davidrios/jade-tmbundle Jade Bonus to get stylus syntax highlighting working run: git clone https://github.com/stylus/stylus.git Stylus