javascript - How can you pass JSON data into a Nunjucks file? -


i have .njk file populate data json file.

currently using webpack.

here json file:

{     "ranking": "colors",     "description": "here ranking of favorite colors",     "rankings": [         {             "rank": 1,             "institution": "red",         },         {             "rank": 2,             "institution": "blue",         },         {             "rank": 3,             "institution": "green",         }     ] } 

in nunjucks file, syntax need use pass in data?

the code worked me:

var json1 = require('./data/data-1.json');  const solutiontemplate = require('./solution.njk');  let togglesolutionfunc = function() {       if (document.getelementbyid('solution-content') != null) {         document.getelementbyid('solution-content').innerhtml = solutiontemplate.render(json1);  

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -