Reputation: 8178
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.
Here's the code:
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.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. 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"]
Upvotes: 4
Views: 1470
Reputation: 8361
You could use JSON.stringify
in conjuction with Unescaped interpolation !{}
to get your array as a string:
"sameAs": !{JSON.stringify(person.links)}
Upvotes: 4