简体   繁体   English

如何将数组从哈巴狗传递给哈巴狗?

[英]How to pass array from pug to pug mixin?

I have a pug template with an array in it, that I want to pass over to a mixin used to populate some schema.org (json) markup. 我有一个带有数组的哈巴狗模板,我想将其传递给用于填充一些schema.org(json)标记的mixin。

Here's the code: 这是代码:

profile.pug 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)

And then in the mixin, I have: 然后在mixin中,我有:

mixin.pug 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}
    }

Everything works great, except the array of 'sameAs' links. 一切都很好,除了'sameAs'链接的数组。 After compiling, I get: 编译后,我得到:

"sameAs": https://link.one,https://link.two

Instead of what I need, which is 而不是我需要的,这是什么

"sameAs": ["https://link.one","https://link.two"]

您可以将JSON.stringify非转义插值 !{}结合使用,以将您的数组作为字符串:

"sameAs": !{JSON.stringify(person.links)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM