簡體   English   中英

如何將JSON數據傳遞給Nunjucks文件?

[英]How can you pass JSON data into a Nunjucks file?

我有一個.njk文件,我想用JSON文件中的數據填充。

目前我正在使用Webpack。

這是我的JSON文件:

{
    "ranking": "Colors",
    "description": "Here is a ranking of my favorite colors",
    "rankings": [
        {
            "rank": 1,
            "institution": "red",
        },
        {
            "rank": 2,
            "institution": "Blue",
        },
        {
            "rank": 3,
            "institution": "Green",
        }
    ]
}

在我的nunjucks文件中,我需要使用什么語法來傳遞這些數據?

對我有用的代碼:

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); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM