# nunjucks

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body></body>
</html>
1
2
3
4
5
6
7
8
9
10
11
let nunjucks = require("nunjucks")
nunjucks.configure({ autoescape: true })
let ret = nunjucks.renderString("hello {{username}}", { username: "zpxe" })
console.log(ret)
1
2
3
4
let nunjucks = require("nunjucks")
nunjucks.configure("views", { autoescape: true })
let ret = nunjucks.render("index.html", { name: "zfpx" })
console.log(ret)
1
2
3
4
let express = require("express")
const path = require("path")
const nunjucks = require("nunjucks")
let app = express()
nunjucks.configure(path.join(__dirname, "views"), {
  autoescape: true,
  express: app,
})

app.get("/", (req, res) => {
  res.render("index.html", { name: "zpxs" })
})
app.listen("3000")
1
2
3
4
5
6
7
8
9
10
11
12
13
let ret = nunjucks.renderString('{{names|join(","')
1