Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果 item.description 未定义或为空,我想默认为“无描述”:
我尝试了以下方法:
<%-: ( item.description | markdown ) || '<p>No description</p>' %> <%-: ( item.description || 'No description' ) | markdown %>
我还可以做些什么?
不确定是否可以||与|EJS 的过滤器混合使用,但您可以添加一个过滤器来完成它:
||
|
ejs.filters.or = function (arg, sub) { return arg || sub; };
<%-: item.description | or:'No description' | markdown %>
我想知道您的问题的代码,为什么带有 ejs 模板表达式的预标记是"<%-" not the "<%="(输出或赋值输出)或"<%=:"(过滤器输出)签名?
"<%-" not the "<%="
"<%=:"
顺便说一句,过滤器调用签名是单个竖线而不是双竖线,您可以随时根据需要调用...