javascript - Express + Jade: render an array of partials -
i have partial button
looks like:
.button button.custom_button(type='button', value='', onclick=#{functionname}) #{functionname}
and render partials of res.renderpartials
function comes npm install express-partial
.
and i want to render on user request. have controller method like:
var express = require('express'); var router = express.router(); router.get('/buttons', function(req, res) { var funcs = ['func1();', 'func2();', 'func3()', .... ]; // funcs.length > 15 res.renderpartials({ // problem #1: how make in loop // problem #2: why returns func[28] rendering result 'partials/button': {functionname: funcs[0]}, 'partials/button': {functionname: funcs[1]}, .......... 'partials/button': {functionname: funcs[28]}, }); });
question: how render button partials @ once? mean pass array res.renderpartials
, avoid encountering each button separated comma.
p.s. supposed that's possible because in jade template can this:
- each video in videos !=partial('partials/video', {title:video.title, artist:video.artist})
example taken here
i though in case can use embedded partials, like
buttons.jade
- each func in #{functions} !=partial('partials/button', {functionname:func})
button.jade
.button button.custom_button(type='button', value='', onclick=#{functionname}) #{functionname}
router
var express = require('express'); var router = express.router(); router.get('/buttons', function(req, res) { res.renderpartials({ 'partials/buttons': {functions: ['func1();', 'func2();', 'func3()', .... ]} }); });
Comments
Post a Comment