gulp-nunjucks-render

How to use nunjucks groupby with different value?

佐手、 提交于 2019-12-25 03:21:33
问题 i can`t figure out how can i gropBy my data from Json when i have this kind of values 2017-10-16 12:07:07 2017-10-16 12:07:07 2017-10-16 15:09:08 2017-10-16 15:09:08 2017-10-16 15:09:08 2017-10-16 15:09:08 2017-10-16 15:09:08 2017-10-16 18:11:09 2017-10-16 18:11:09 2017-11-29 17:26:57 2017-11-29 17:26:57 2017-11-29 17:26:57 2017-11-29 19:31:03 My template <div class="container"> <div class="row"> <div class="col-5"> {% for date , block in block | groupby("date") %} <div class="date">{{date

How can i multiply data in nunjuncks?

旧巷老猫 提交于 2019-12-24 21:03:30
问题 for instance <div class="price">{{blocks.quantity}} x {{blocks.price}} </div> i want to multiply price by quantity data from Json file. 回答1: var nunjucks = require('nunjucks'); var env = nunjucks.configure(); env.addFilter('mysum', function (arr) { return arr .map(e => e.quantity * e.price) // get amount to each e .reduce((sum, e) => sum + e, 0) // calc total summa }); var data = [ {price: 10, quantity: 2}, {price: 2, quantity: 7}, {price: 5, quantity: 11} ] var res = env.renderString(`{{

Nunjucks dynamic page template

只愿长相守 提交于 2019-12-23 04:32:33
问题 i'm using nunjucks (gulp) as templating language and i want to build a dynamic page template. This is my Json: "pages": [ { uname: "Welcome", title: "Page 1 Headline" }, { uname: "About", title: "Page 2 Headline" } ] Currently i have a static page (html) template for each page: {% extends "layout.html" %} {% set active_page = "Welcome" %} //<- This needs to be dynamicly {% block content %} <h1>{{ page[0].title }}</h1> //<- This needs to be dynamicly My first thought was to read the url