swig-template

How to output JSON with swig in nodejs

孤人 提交于 2020-01-02 03:49:45
问题 I tried json filter, but I get "json" filter not found error. What I'm I doing wrong? Error: Filter "json" not found at Object.exports.wrapFilter (......./node_modules/swig/lib/helpers.js:310:11) <script type="text/javascript"> {{ places|json }} </script> object is passed from mongodb this.displayMainPage = function(req, res, next) { "use strict"; places.getPlaces(10, function(err, results) { "use strict"; if (err) return next(err); return res.render('places_template', { places: results }); }

How an included partial insert code into parent's block?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 01:45:24
问题 What I want to do is to add the scripts block in dropdown.swig added to scripts block in template.swig . My usage pattern could be wrong. I've a working code using ejs-locals template engine but I would like to switch to swig . Here's the code: <!-- template.swig, to be extended --> <body> <header> {% include "navbar.swig" %} </header> <!-- template scripts --> <script src="/scripts/jquery.min.js"></script> {% block body %}{% endblock %} <!-- child scripts --> {% block scripts %}{% endblock %

access json data using swig-template

偶尔善良 提交于 2019-12-23 02:48:05
问题 { "_id": "1", "style": "13123", "category": "dress", "colors": { "Black": { "prestock": 50, "instock": 60, "inactive": 0 }, "Blue": { "prestock": 30, "instock": 0, "inactive": 0 }, "Red": { "prestock": 10, "instock": 60, "inactive": 0 } } } i'm using swig-template to access 'colors' object i need to express each color in this list-format: Black Blue Red how can i access this json? ps. i tried other ways but no luck, what i have is {{style_list.colors|sort}} which gives me like this: Black,

Cannot render swig templates in Express

北城余情 提交于 2019-12-22 06:29:02
问题 So I'm trying to use consolidate.js to render swig templates with express, but I get the following error when I try to "extend" one template from another: Error: ENOENT, no such file or directory '//one.html In my app.js file I setup swig as my rendering engine (only including relevant code): var consolidate = require('consolidate'); app.set('view engine', 'html'); app.set('views', __dirname + '/views'); app.engine('.html', consolidate.swig); app.get('/test', function(req, res) { res.render(

JSON.parse() in Swig (Node.js)?

空扰寡人 提交于 2019-12-12 20:20:35
问题 I'm trying to switch from Jade to Swig (lured by Swig's insane performance) as my Express template engine when I got stuck here — I'm sending an array of serialized JSON from Express into Swig and retrieve the data in Swig using this loop here: <ul id = "list"> {% if items %} {% for item in items %} {{ JSON.parse( item ).title }} {% endfor %} {% endif %} </ul> ... but I get this: SyntaxError: Unexpected token ) at Object.Function (unknown source) at createTemplate (/home/vijay/node_modules

How to include a partial into another partial's block?

旧时模样 提交于 2019-12-10 11:42:49
问题 I use Swig as a template engine. I need to include a partial but only into another partial's block. But Swig includes it just below, ignoring a block tag. Here is how it looks: 1. layout.html <!DOCTYPE html> <html> <head> {% block title %}{% endblock %} {% block headtag %} <link rel='stylesheet' href='/assets/css/global.css' /> <link rel='stylesheet' href='/bower_components/bootstrap/dist/css/bootstrap.css' /> <script src="/bower_components/jquery/dist/jquery.js"></script> <script src="/bower

access json data using swig-template

不羁的心 提交于 2019-12-06 15:40:45
{ "_id": "1", "style": "13123", "category": "dress", "colors": { "Black": { "prestock": 50, "instock": 60, "inactive": 0 }, "Blue": { "prestock": 30, "instock": 0, "inactive": 0 }, "Red": { "prestock": 10, "instock": 60, "inactive": 0 } } } i'm using swig-template to access 'colors' object i need to express each color in this list-format: Black Blue Red how can i access this json? ps. i tried other ways but no luck, what i have is {{style_list.colors|sort}} which gives me like this: Black, Blue, Red Use the built-in JavaScript method Object.keys <ul> {% for color in Object.keys(colors) %} <li>