[英]How to disable default trim in writing variable ejs, node.js?
When I writing variable in EJS table from database, it is written by ejs template with default trim. 当我从数据库中写入EJS表中的变量时,它是由带有默认修剪的ejs模板编写的。 I want to write variable that come database without default trim.
我想编写没有默认修剪的数据库变量。
I examined ejs template document( https://ejs.co ) but they did not help me. 我检查了ejs模板文档( https://ejs.co ),但他们没有帮助我。
<%- fetchpost[i].p_content %>
-> with HTML 带有HTML的
<%- fetchpost[i].p_content %>
- >
<%= fetchpost[i].p_content %>
-> only string <%= fetchpost[i].p_content %>
- >只有字符串
EJS doesn't seem to trim data by default. EJS似乎默认不修剪数据。 If your content has spaces, they should be preserved.
如果您的内容有空格,则应保留它们。 I created a test for this: https://noderun.com/alex/ejs-trim-test/
我为此创建了一个测试: https : //noderun.com/alex/ejs-trim-test/
However, HTML doesn't render multiple spaces in a row when rendered by a browser (that could be your problem). 但是,HTML在浏览器呈现时不会在一行中呈现多个空格(这可能是您的问题)。 In that case you could try:
在这种情况下,您可以尝试:
<%- content.replace(/ /g, " ") %>
This replaces spaces with HTML non-breaking spaces. 这将使用HTML不间断空格替换空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.