我一直在使用快速Web框架的Node.js的,并使用降价解析器一直chjj/marked以解析降价到HTML中。我还能够使用 Express 呈现此降价。我通常在 Express 项目中使用 EJS 模板,我希望能够做的是使用带有 Markdown 的 EJS。
理想情况下,我希望能够使用 EJS 中通常使用的编译时包含,此处显示了一个示例:
<% include header.html %>
<h3>User List -- Located in users.html</h3>
<ul id="users">
<% users.forEach(function(user){ %>
<li><%= user.name %> -- <%= user.email %></li>
<% }) %>
</ul>
<% include footer.html %>
Run Code Online (Sandbox Code Playgroud)
如果我可以在我的 EJS 模板中包含如下所示的 Markdown 文件,那就太好了:
<% include markdown-file.md %>
Run Code Online (Sandbox Code Playgroud)
能够在 Markdown 中使用 EJS 语法或提供某种访问 Markdown 中变量的方法也很好。这样的事情有可能吗?如果不是,对我来说,在 EJS 模板中对我的内容使用 Markdown 的最简单方法是什么?
2013 年 5 月 19 日编辑:我真的很想做这样的事情以用于我自己的项目,所以我不得不尝试将 Markdown 与 EJS 结合起来。 …
I have a index.html with a which sends a text to a PHP code. This PHP sends it again by POST (curl) to a Node.js server, inserted in a JSON message (utf8-encoded)
//Node.js server file (app.js) -- gets the json and shows it in a <script> to save it in client JS
render(index, {json:{string:"mystring"}})
//Template to render (index.ejs)
var data = <%=JSON.stringify(json)%>;
Run Code Online (Sandbox Code Playgroud)
So that I can pass those variables in the JSON to data. JSON is way bigger than here, …
我正在使用 Koa 框架和 EJS 模板来呈现视图。我需要向视图发送一些 html 元素值。但是 ejs 库正在将它们转换为 html 实体。我正在关注他们在https://www.npmjs.org/package/koa-ejs中的说法
在我的 js 文件中:
yield this.render('ejs file name', {
a: 'hi',
b: '<a href="hi">hi</a>'
});
Run Code Online (Sandbox Code Playgroud)
我的视图文件:
<%=a %>
<%=b %>
Run Code Online (Sandbox Code Playgroud)
运行代码后我得到了什么:
hi
<a href="hi">hi</a>
Run Code Online (Sandbox Code Playgroud)
但我需要的<a href="hi">hi</a>不是价值<a href="hi">hi</a>
有没有人有任何建议如何做到这一点?
我有一个结构良好的大型xml,我想要像ejs那样的模板.
<foo>
<url><%= url %></url>
<foo>
Run Code Online (Sandbox Code Playgroud)
但如果我这样做
res.render('template.xml', { url: 'http://foo.com' })
Run Code Online (Sandbox Code Playgroud)
我正进入(状态
Error: Cannot find module 'xml'
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议如何处理它?我只需要在已经形成的xml中插入值,我不希望通过模式将对象序列化为xml.
我有一个节点JS服务器查询的MongoDB,然后渲染返回到EJS模板:
res.render('graphFabric.ejs', {'iBeacons':[(beacon)]});。
当我尝试使用从我的模板恢复 JSON 时
<%=iBeacons%>
,'(单引号)显示为' 例如:udid: 'b9407f30f5f8466eaff925556b57fe6d',
如何解决这个问题,因为它破坏了我的 JSON 结构?
我正在尝试使用Node.JS将过滤器应用于EJS,我收到以下错误.我希望消息内容以大写形式显示.
D:\Apps\Templating\ejs>node server.js
D:\Apps\node_modules\ejs\lib\ejs.js:470
throw e;
^
SyntaxError: Unexpected token : while compiling ejs
at Function (native)
at Object.Template.compile (D:\Apps\node_m
odules\ejs\lib\ejs.js:460:12)
at Object.compile (D:\Apps\node_modules\ej
s\lib\ejs.js:288:16)
at handleCache (D:\Apps\node_modules\ejs\l
ib\ejs.js:147:16)
at Object.exports.render (D:\Apps\node_mod
ules\ejs\lib\ejs.js:315:10)
at Object.<anonymous> (D:\Apps\Templating\
ejs\server.js:3:17)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
Run Code Online (Sandbox Code Playgroud)
这是我的code- server.js:
var ejs = require('ejs');
var template = "<%=: message | upcase %>";
console.log(ejs.render(template,{message : 'hello ejs with filter'}));
Run Code Online (Sandbox Code Playgroud)
我已经使用包管理器安装了ejs,它适用于带有过滤器(:)的普通脚本.下载的EJS版本是最新版本2.3.3,节点版本是0.12.4.
npm install ejs
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.提前致谢.
我的项目是这样的:
views/
layout.ejs
data/
US-states.json
public/
index.html
Run Code Online (Sandbox Code Playgroud)
US-states.json 看起来像这样
{
"DC": "District of Colombia",
"NY": "New York",
etc...
}
Run Code Online (Sandbox Code Playgroud)
如何将这个 json 数据拉入layout.ejs以在这样的循环中呈现一些 div?
<div>DC: District of Colombia</div>
<div>NY: New York</div>
Run Code Online (Sandbox Code Playgroud)
我试过这样的事情,但我在谷歌搜索解决方案时遇到了麻烦:
var data = JSON.parse('./../data/US-states.json')
<% for(var p in data) {%>
<div>p: data[p]</div>
<% } %>
Run Code Online (Sandbox Code Playgroud) 我正在 EJS 模板中从 Mognodb 获取内容。我的描述字段包含超过 500 个字符,但我只想在我的视图中显示 50 个字符。
谁能告诉我怎么做。
我有一个 node.js 应用程序,我想每天早上 8 点从这个应用程序向少数人发送一封 HTML 电子邮件。我有一个dashboard.ejs 文件,它从数据库中获取一些数据并在引导仪表板模板中显示它们。我想将此dashboard.ejs 作为HTML 电子邮件发送,其中包含数据库中的所有数据,并且样式与从应用程序加载该dashboard.ejs 时相同。
我已准备好 cron 作业和邮件程序功能。我无法做的就是通过电子邮件将dashboard.ejs 文件作为HTML 发送。这可以吗?如果是,任何帮助将不胜感激。
var mailer = require('express-mailer');
var CronJob = require('cron').CronJob;
mailer.extend(app, {
from: 'user@gmailcom',
host: 'smtp.gmail.com',
secureConnection: true;
port: 465, // port for secure SMTP
transportMethod: 'SMTP',
auth: {
user: 'user@gmail.com',
pass: 'password'
}
});
var job = new CronJob('00 49 * * * *', function() {
console.log('This runs on 49th second of every min every hour every day every month every year')
app.mailer.send('dashboards/dashboard', {
to: …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个可存储用户名,国家和用户消息sin mongodb的留言簿应用程序,连接正常,我可以在数据库中提交这3个信息(用户名,国家和消息)。我的问题是将消息发送到“ guestbook.ejs”页面。
如果有人能给我有关我遇到的问题的线索,我将不胜感激。
SyntaxError: Unexpected token return in /Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/views/pages/guestbook.ejs while compiling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
at Object.Function (<anonymous>)
at Object.Template.compile (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/ejs/lib/ejs.js:524:12)
at Object.compile (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/ejs/lib/ejs.js:338:16)
at handleCache (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/ejs/lib/ejs.js:181:18)
at tryHandleCache (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/ejs/lib/ejs.js:203:14)
at View.exports.renderFile [as engine] (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/ejs/lib/ejs.js:412:10)
at View.render (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/express/lib/view.js:126:8)
at tryRender (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/express/lib/application.js:639:10)
at EventEmitter.render (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/express/lib/application.js:591:3)
at ServerResponse.render (/Users/mesfint/Desktop/MEAN_DEV'T/Guestbook-application/node_modules/express/lib/response.js:960:7)
Run Code Online (Sandbox Code Playgroud)
guestbook.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<% include ../partials/head %>
</head>
<body class="container">
<header>
<% include ../partials/header %>
</header>
<main>
<div …Run Code Online (Sandbox Code Playgroud)