Questions tagged [nunjucks]

A rich and powerful templating language for JavaScript

Nunjucks is a port of jinja2.

Tag questions with Nunjucks if you have issues with any of the following functionalities in the templates:

  • Variables
  • Filters
  • Template Inheritance
  • Tags if for asyncEach1 asyncAll macro set extends block include import raw
  • Keyword Arguments
  • Comments
  • Whitespace Control
  • Expressions Math Comparisons Logic`` If Expression Function Calls`
  • Autoescaping
  • Global Functions range([start], stop, [step]) cycler(item1, item2, ...itemN) joiner([separator])
  • Builtin Filters

official website

510 questions
0
votes
0 answers

Access value from key in Nunjucks

If you have the following set in Nunjucks: {% set breakpoints = { 'lap': 768px, 'desk': 1024px } %} Is there a way to access the value of width for lap, without actually looping through the values? Something like: {{ breakpoints | lap }} ?…
patrickzdb
  • 928
  • 1
  • 10
  • 26
0
votes
0 answers

Pass data from json to variable express nunjucks

This is one of those questions that have been asked a few times but still has no good answers. I cant work out how to retrieve my data in stored in seperate json files for use by the variables i define in my partials and macros. Note I am trying to…
JPB
  • 592
  • 2
  • 6
  • 28
0
votes
1 answer

Async template preload with Nunjucks

Nunjucks uses getTemplate() to preload and precompile templates - env.getTemplate('page.html', true); Documentation says also "If using any async loaders, you must use the async API." but there's no any code example. Can anyone tell what to use…
Jury
  • 431
  • 5
  • 15
0
votes
1 answer

NodeJs - Rendering same page after multiple SELECT queries

I have below codes in my index.js file. I can print data of profile table. And i need to print data of resume table also in same (index.njk) page. But i couldn't. I also found a similar question but i am new and couldn't modify those codes according…
Can Aslan
  • 53
  • 2
  • 11
0
votes
1 answer

Using templates variables inside an angularJS script?

I'm using Nunjucks to render a template overtime something hits the right URL. This is a piece of that template:

Select some text

{% for i in result %}
Amir A.Eitan
  • 183
  • 1
  • 12
0
votes
1 answer

Calculate the difference between two times from MongoDB in NodeJS and send to nunjucks

I have been using this post as a guide in order to create some NodeJS code to connect to a MongoDB instance, authenticate, then calculate the difference between two timestamps, and then send this to a nunjucks template. My code is: app.get('/test',…
ColSan
  • 11
  • 4
0
votes
0 answers

Rendering Nunjuck templates from Express

My folder structure is defined as ├── core | ├── main.css | └── base.njk ├── preview | ├── img | ├── css | ├──routes | | └──index.js | ├── views | | ├── preview.njk | └── server.js ├── templates | ├── login | | └──…
user2473015
  • 1,392
  • 3
  • 22
  • 47
0
votes
2 answers

Node.js - print result from sql

I am trying to run a select query from db and print results. But even i see result in console i don't see in index page. (Hovewer i see result in console but it is also doesn't show correctly. I have 2 rows in db but i see 3 lines for each row. So…
Can Aslan
  • 53
  • 2
  • 11
0
votes
1 answer

Populating navigation items from array in Nunjucks

I need to populate breadcrumb navigation with the data I defined inside set breadcrumb. So, my code looks like this: Breadcrumb items: {% set breadcrumb = [{ name : 'Item name 1'}, { name : 'Item name 2'}, { name : 'Item name 3'}] %} And the loop…
momciloo
  • 887
  • 1
  • 11
  • 24
0
votes
1 answer

Nunjucks extends directive not working with template in separate directory using express?

I am setting up the nunjucks templating with my express app below is my directory structure for a project . nunjucks-project |__ api |__ node_modules |__ views |__ templates |__ layouts |__ default.html |__…
kailash yogeshwar
  • 836
  • 1
  • 9
  • 26
0
votes
1 answer

can't pass object to html with nunjucks

I want to use Nunjucks to pass data from a mongoDB server to my html file to render on load. App.js app.get('/', function(req, res) { database.retrieveComments(req, function(err,result) { console.log(result); …
Amir A.Eitan
  • 183
  • 1
  • 12
0
votes
1 answer

Nunjucks iterate over items in an array to display items in object

In javascript I can loop over an array to output my object as shown below. var myArr = ["one","two","three"] var myObj = { "one": { "title": "ones", "desc": "this is one" }, "three": { "title": "threes", "desc": "this is…
ak85
  • 4,154
  • 18
  • 68
  • 113
0
votes
1 answer

Call parent on extending nunjucks.FilesystemLoader

I simply extends the Filesystem loader like: var nunjucks = require('nunjucks'); MyLoader = nunjucks.FileSystemLoader.extend({ getSource: function(name) { return this.parent().getSource(name); } }); how ever I…
egig
  • 4,370
  • 5
  • 29
  • 50
0
votes
0 answers

Unable to load css file

I am using express and nunjucks template engine for building a node app. templateEngine.js var nunjucks = require('nunjucks'); module.exports = function (app) { // store environment env var env = nunjucks.configure(['views/www'], { …
maverick
  • 73
  • 1
  • 8
0
votes
1 answer

Multiple data files with Nunjucks

How do I use multiple data files in Nunjucks? — an array of strings does not work for me; gulp.task('nunjucks', function() { return gulp.src('src/pages/**/*.+(html|nunjucks)') .pipe(data(function() { /*DOESN'T WORK*/ return…
Scott Simpson
  • 3,832
  • 3
  • 27
  • 35