node.js - Set CSS path for Jade layouts -


i'd set css path in express application in order use 1 in jade layouts. however, don't know how do, try use "app.set('csspath', __dirname+'/public/admin/css/')" doesn't work because can not use "app.get()" in external controllers.

my layout _layout.jade :

!!! 5 html(lang='fr')   head     meta(charset='utf-8')     link(href='admin/css/screen.css', media='screen, projection', rel='stylesheet', type='text/css')   body     .container       h1 wellcome forest administrator       .space20       block content       .clear.space20   script(type='text/javascript', src='admin/js/jquery.js') 

my page edit.jade :

extends ../_layout  block content   .block.half.first     h2 add post 

and i'd use :

link(href='+mycsspath+', media='screen, projection', rel='stylesheet', type='text/css') 

not sure if want can use

res.locals.csspath = 'string path'; 

and csspath available in template.

besides don't need __dirname+'/public/. part because when page rendered browser /public/ /

[edit] if want have variable available in routes, declaring once, can create small middleware

var express = require('express'); var app = express(); var app.configure(function(){      app.use(express.bodyparser());     app.use(express.methodoverride());     // .. , other tipical configuration      //this small middleware variables must available in paths      app.use(function(req, res, next) {         res.locals.csspath = 'path css directory';         next();     }); }); //from here typical route declarations   app.get('/', function(req, res) { res.render('someview'); }); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -