Go 模板:如何将 array[]string 打印到 <script type="application/ld+json">
Go template : Howto print array[]string to <script type="application/ld+json">
[![在此处输入图片描述][1]][1]我有 1 个数组字符串包含许多图片 url,如何将其显示到 application/ld+json
请帮我解决这个问题!
谢谢大家!
这是可变类型切片,包含很多imageUrl
images := []string{
"abc.com/1.jpg",
"abc.com/2.jpg",
"abc.com/3.jpg",
"...",
}
这是 html
中的脚本
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{$currentUrl}}"
},
"headline": "{{$postTile}}",
"image": [
"*i want show imageUrl at here*",
"*i want show imageUrl at here*",
"*i want show imageUrl at here*",
]
}
如@mkopriva 评论所述,只需对图像进行范围检查:
{{range .ImageSlice}}{{.}}{{end}}
[![在此处输入图片描述][1]][1]我有 1 个数组字符串包含许多图片 url,如何将其显示到 application/ld+json
请帮我解决这个问题!
谢谢大家!
这是可变类型切片,包含很多imageUrl
images := []string{
"abc.com/1.jpg",
"abc.com/2.jpg",
"abc.com/3.jpg",
"...",
}
这是 html
中的脚本<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{$currentUrl}}"
},
"headline": "{{$postTile}}",
"image": [
"*i want show imageUrl at here*",
"*i want show imageUrl at here*",
"*i want show imageUrl at here*",
]
}
如@mkopriva 评论所述,只需对图像进行范围检查:
{{range .ImageSlice}}{{.}}{{end}}