簡體   English   中英

如何將數組從哈巴狗傳遞給哈巴狗?

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

我有一個帶有數組的哈巴狗模板,我想將其傳遞給用於填充一些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中,我有:

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非轉義插值 !{}結合使用,以將您的數組作為字符串:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM