在Jade中,为什么我有时会按原样使用变量,而在其他时候必须将它们包含在#{......}中?

Ris*_*ran 2 express pug

看下面的代码

        for story in book 
            if story.title.length < 140
                - var storyTitle = story.title;
            else
                - var storyTitle = story.title.substring(0, 140) + '...';

            .tiles
                a(href= 'http://' + story.link)
                    img(src=story.thumbnail, width='150', height='150')
                p Title: #{storyTitle}
                p Date: #{story.time}
                p Author: #{story.authorName}
Run Code Online (Sandbox Code Playgroud)

这对我有用.然而,它告诉我,在tmes我可以使用story.attribute,并且在必须使用#{story.attribute}的地方.

例如.如果我使用该线

p Title: storyTitle
Run Code Online (Sandbox Code Playgroud)

没有胡须,它只是在浏览器中打印字符串"Title:storyTitle".

另一个例子,如果我使用img(src=#{story.thumbnail}, width='150', height='150')它,它不起作用,我在我的浏览器中得到一个HTML字符串(%20%20 ......东西...).

什么赋予了什么?

zem*_*rco 7

简单地说

等号后(=),内部代码块没有花括号.其他地方都在使用#{}.