【问题标题】:Jade - Print many variables in one lineJade - 在一行中打印多个变量
【发布时间】:2016-06-23 04:08:12
【问题描述】:

我正在尝试打印从控制器传递的几个变量以在一行中查看。
变量的内容类似于“xyz”,其中 tag 是有效的 html 标记。
我现在做的是——

div
  != (notification.content + notification._.publishedDate.format('MMMM Do, YYYY'))

但是,这会将 div 打印在两行上。
生成的html内容是-

<div>
    <p>School is closed tomorrow&nbsp;<a href="http://www.booking.com">link</a></p>
     March 7th, 2016
</div>

另外我做不到-

p= (notification.content + notification._.publishedDate.format('MMMM Do, YYYY'))

因为输出是 HTML 格式的 -

<p>&lt;p&gt;School is closed tomorrow&amp;nbsp;&lt;a href="http://www.booking.com"&gt;link&lt;/a&gt;&lt;/p&gt;March 7th, 2016</p>

【问题讨论】:

  • 我不确定您要做什么...您想将所有变量连接在 1 行上,并使用转换后的 html 标签,但内容中也有 &lt;p&gt; 标签?因此,如果您想让它上线,您需要确保 notification.content 中没有“阻止”标签...
  • 是的就是这样
  • 就像我说的,确保内容中没有

    标记,或者在连接变量的地方设置 div 的样式并设置 p{ display: inline-block; }

标签: node.js express pug keystonejs


【解决方案1】:

嘿!

查看一些使用 Jade/HTML 显示消息的方法。

请测试这些方法并在您的项目中使用最好的


声明变量

// Variable with `<p></p>`
- var notification = {content: '<p>School is closed tomorrow <a href="http://www.booking.com">link</a></p>', publishedDate: '2016-03-07'}

// Variable withOUT `<p></p>`
- var test = {content: 'The message <a href="#">link</a>', publishedDate: '2016-03-07'}

1) 返回转义文本

div #{notification.content} #{notification.publishedDate}

// Return | escaped string:
// <p>School is closed tomorrow <a href="http://www.booking.com">link</a></p> 2016-03-07

2) 返回 HTML 代码(未转义 | 真实标签)

div !{notification.content} !{notification.publishedDate}

// Return | unescaped (2 lines)
// School is closed tomorrow link
// 2016-03-07

3) 返回 HTML 内联代码(也未转义)

您需要修改数组条目。请参阅上面的 var "test"(关于声明变量):

div: p !{test.content} !{test.publishedDate}

// Return | unescaped (1 line)
// The message link 2016-03-07

如果适合您,请尝试应用您自己的变量和规则。
我正在学习玉。希望能帮到你。

- 有任何疑问在这里评论或与我交谈@devromulobastos

【讨论】:

    猜你喜欢
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2014-03-15
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多