nunjucks

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

gulp-nunjucks-html + gulp-data not compiling on watch

£可爱£侵袭症+ 提交于 2019-12-23 02:06:12
问题 I've written a gulp task to take data from json files and process it as html. When I first run the build this works like a charm, however I've set up a watch task to also do this and although it will rebuild the nunjucks file into html, it seems to ignore the json until the next full build (even though all the watch does is run the same task) here is my task: // Process nunjucks html files (.nunjucks) gulp.task('nunjucks', function() { 'use strict'; return gulp.src('src/html/pages/**/*

gulp-nunjucks-html + gulp-data not compiling on watch

一个人想着一个人 提交于 2019-12-23 02:06:11
问题 I've written a gulp task to take data from json files and process it as html. When I first run the build this works like a charm, however I've set up a watch task to also do this and although it will rebuild the nunjucks file into html, it seems to ignore the json until the next full build (even though all the watch does is run the same task) here is my task: // Process nunjucks html files (.nunjucks) gulp.task('nunjucks', function() { 'use strict'; return gulp.src('src/html/pages/**/*

How to use nunjucks macros in the browser client-side?

喜欢而已 提交于 2019-12-21 04:54:12
问题 I'm able to use client-side templating for nunjucks as I precompile from node.js and expose JS template files. I call the client-side templates like so: nunjucks.render('partials/some-template.html', { abc: 123 }) and get a string back. How can I call macros as I've tried but am doing this wrong. Macros are first declared on the page in terms of node.js then called successive times for example in Node.js: {% include 'macros/checkbox.html' %} ... {{ checkbox('you cool?', 'cool', false) }} {{

Convert integer to string Jinja

被刻印的时光 ゝ 提交于 2019-12-17 17:53:36
问题 I have an integer {% set curYear = 2013 %} In {% if %} statement I have to compare it with some string. I can't set curYear to string at the beginning because I have to decrement it in loop. How can I convert it? 回答1: I found the answer. Cast integer to string: myOldIntValue|string Cast string to integer: myOldStrValue|int 来源: https://stackoverflow.com/questions/19161093/convert-integer-to-string-jinja

Nunjucks: Retrieve data from variables in json file (npm only)

天大地大妈咪最大 提交于 2019-12-12 06:38:19
问题 I posted a similar question recently but did not get enough of a response to understand my problem. It seems like a question that gets asked a lot but never really answered properly. Using npm only (no gulp or grunt) with nunjucks how do you access the variables you define in a json file for use in your views when precompiling? Scenario: VIEWS view1.njks: <h1>{{var1}} view2.njks: <h1>{{var1}}, <h2>{{var2}} view3.njks: <h1>{{var2}} DATA variables.json: var1: red, var2: blue. CONFIG app.js:

Globbing in template path not working in nunjucks with gulp

谁说胖子不能爱 提交于 2019-12-12 04:29:49
问题 I'm using this gulp plugin to use nunjucks to make HTML management easier. https://github.com/carlosl/gulp-nunjucks-render gulp.task('default', function () { return gulp.src('src/templates/*.html') .pipe(nunjucksRender({ path: ['src/templates/'] // String or Array })) .pipe(gulp.dest('dist')); }); I want to keep my templates and partials of specific pages under page's directory in different folders so I tried this to keep the path as path: ['src/templates/', 'src/common-partials/', 'src/pages

Loop through object properties nunjucks

主宰稳场 提交于 2019-12-09 15:08:39
问题 I've got following model: items: { someId1: { property1.... }, someId2: {...}, someIdN: {...} } I would like to get a for -loop in my template (nunjucks) which goes through all the "someId's". Does anyone have any idea how? A normal for-loop does not work since it's not an array and since I use the "someId.." for a reference in another template I cannot put it to an array. Any help would be awesome. 回答1: This answer is actually right on the Nunjucks homepage: <ul> {% for name, item in items %

Loop by integer value with Nunjucks Templating

拜拜、爱过 提交于 2019-12-09 14:11:07
问题 I'm quite new to nunjucks and from what I have read this is not possible, but I was wondering if anyone had come up with a way of doing this. I am basically looking to perform a for loop in a nunjucks template based on a value rather than an object's size. Say you pass the following data to a template. Assume the number of rooms value is the value of a selected option from a <select> element : data : { numberOfRooms : 4 } In traditional JS I could write a for loop and limit the loop based on

How to execute a (safe) bash shell command within setup.py?

别来无恙 提交于 2019-12-09 01:21:12
问题 I use nunjucks for templating the frontend in a python project. Nunjucks templates must be precompiled in production. I don't use extensions or asynchronous filters in the nunjucks templates. Rather than use grunt-task to listen for changes to my templates, I prefer to use the nunjucks-precompile command (offered via npm) to sweep the entire templates directory into templates.js. The idea is to have the nunjucks-precompile --include ["\\.tmpl$"] path/to/templates > templates.js command