如何将EJS模板引擎与Nestjs一起使用?
我想将EJS用作Nestjs中的模板引擎。使用Express,我可以在主文件中配置EJ:
app.set("view engine", "ejs");
如何最好用Nestjs实现此功能? Nestjs不使用 .set
方法运送。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
app.setViewEngine('ejs')
inmain.ts
中配置该。首先,安装它:在下面的行中,您会告诉Express,
public
目录将用于存储静态资产,views
将包含模板,并且EJS
模板引擎应用于渲染HTML输出。以下是您将如何在控制器中渲染模板。您正在渲染
index.ejs
,并将消息传递
作为参数。最后,您将使用该传递的
消息
变量index.ejs
像这样:您可以在官方文档。
You can configure that with the help of
app.setViewEngine('ejs')
inmain.ts
. First, install it:With the lines below, you would have told Express that the
public
directory will be used for storing static assets,views
will contain templates, and theejs
template engine should be used to render HTML output.And below is how you would render a template in a Controller. You are rendering
index.ejs
and passingmessage
as a parameter.Finally, you would use that passed
message
variable insideindex.ejs
like this:You can read more on the official documentation.