node.js - Use jade mixin inside code block -


is there way use jade mixin inside javascript code block?

i have next use case:

mixin yyyymmdd(date)   = date.getfullyear() + '-'   = ('0' + (date.getmonth() + 1)).slice(-2) + '-'   = ('0' + date.getdate()).slice(-2) 

so need use mixin inside

input(    value=yyyymmdd(date) ) 

update: had remake mixins js functions, looks similar next:

- function yyyymmdd(date)     - var fldate = date.getfullyear() + '-';     - fldate += ('0' + (date.getmonth() + 1)).slice(-2) + '-';     - fldate += ('0' + date.getdate()).slice(-2);     - return fldate; 

the easiest way is, write code on server, can use other syntax, instance coffeescript or better in case, libraries moment

when render template, add helper object locals:

var moment = require('moment'); var yyyymmdd = function(date) {   return moment(date).format('yyyymmdd'); }  // express code  app.get('/test', function(req, res, next) {   var locals = getlocalsfortest();   locals.helpers = {     yyyymmdd: yyyymmdd   };   res.render('template.jade', {locals: locals}); }); 

and in template can call this

input(value=helpers.yyyymmdd(date)) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -