我有一个包含数组的pug模板,我想把它传递给一个用来填充一些schema.org (json)标记的mixin。
代码如下:
profile.pug
include ../components/bio-seo
- var person = {}
- person.title = "Name, title of person"
- person.url = "https://page.url..."
- person.image = "https://images.url..."
- person.links = ["https://link.one...","https://link.two..."]
+bio-seo(person)然后在混音中,我有:
mixin.pug
mixin bio-seo(person)
title= title
link(rel='canonical', href=url)
script(type="application/ld+json").
{
"@context": "http://schema.org",
"@type": "Person",
"image": "#{person.image}",
"url": "#{person.url}",
"sameAs": #{person.links}
}除了“sameAs”链接数组之外,一切都运行得很好。编译后,我得到:
"sameAs": https://link.one,https://link.two而不是我需要的,也就是
"sameAs": ["https://link.one","https://link.two"]发布于 2018-01-25 19:13:30
您可以将JSON.stringify与Unescaped interpolation !{}结合使用,以获得字符串形式的数组:
"sameAs": !{JSON.stringify(person.links)}https://stackoverflow.com/questions/48408963
复制相似问题