[英]Object properties with special characters in EJS
I am writing a website where I have a language file looking like the following:我正在编写一个网站,其中有一个如下所示的语言文件:
replace = {
"x:a": "Hello",
"x:b": "World!",
"y:c.d": "Another text"
}
And now I want to pass this object to my express page (which is using EJS) to replace the template placeholders:现在我想将此对象传递给我的快速页面(使用 EJS)来替换模板占位符:
app.js应用程序.js
res.render('index.ejs', replace)
index.ejs索引.ejs
<html>
<head>
</head>
<body>
<%= x:a %>
<%= x:b %>
<%= y:c.d %>
</body>
</html>
But obviously this isn't working, because x:a is not a valid name, so how can I call these names in my index.ejs?但显然这不起作用,因为 x:a 不是有效名称,所以我如何在 index.ejs 中调用这些名称?
Pass an object instead, then access properties on it.而是传递一个对象,然后访问它的属性。
res.render('index.ejs', { replace })
<%= replace['x:a'] %>
<%= replace['x:b'] %>
<%= replace['y:c.d'] %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.