我有一个带有数组的 pug 模板,我想将其传递给用于填充某些 schema.org (json) 标记的 mixin。
代码如下:
配置文件.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 中,我有:
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"]
最佳答案
您可以将 JSON.stringify
与 Unescaped interpolation 结合使用!{}
将您的数组作为字符串获取:
"sameAs": !{JSON.stringify(person.links)}
关于html - 如何将数组从 pug 传递到 pug mixin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48408963/