如何在视图中包含html代码? [英] How to include html code in a view?

查看:97
本文介绍了如何在视图中包含html代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 express.js EJS 作为模板引擎。
我不明白如何使用部分,我已经看到例子,但作者使用JADE模板引擎,所以我不知道如何应用它与EJS。

I'm using express.js and EJS as template engine. I don't understand how to use partials, I have seen at the examples but the author used JADE template engine, so I don't know how to apply it with EJS.

我有一个简单的视图,命名为:test.ejs和另一个.ejs文件,名为part1.ejs

I have a simple view named: test.ejs and another .ejs file named part1.ejs

我需要在测试中显示part1.ejs。 ejs。

I need to show part1.ejs inside test.ejs.

我尝试将<%partial('part1',{})%> test.ejs),但没有发生任何事情,它不包括该文件。

I tried putting <% partial('part1', {}) %> (into test.ejs) but nothing happen, It does not include that file.

有人可以举个例子吗?

谢谢!

推荐答案

您的情况下正确的代码将是:

The correct code in your situation would be:

<%- partial('part1') %>

如果要包含未​​转义的HTML,请使用<% - 如果您想要转义HTML(包含部分内容时不连续),则可以使用<%=

If you want to include unescaped HTML use <%- and if you want to escape HTML (unlinkely though when including a partial) you can use <%=.

资源:

Node.js - EJS - 包括部分

http://groups.google.com/group/express-js/browse_thread/thread/62d02af36c83b1cf

这篇关于如何在视图中包含html代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆