Home > Software design >  Go template : Howto print array[]string to <script type="application/ld json">
Go template : Howto print array[]string to <script type="application/ld json">

Time:10-01

[![enter image description here][1]][1]I have 1 array string contains many image url, how to display it in to application/ld json

Please help me for resolve this problem!

Thanks all!

This is variable type slice contain many imageUrl

images := []string{
            "abc.com/1.jpg",
            "abc.com/2.jpg",
            "abc.com/3.jpg",
            "...",
        }

This is script in 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*",
    ]
}

CodePudding user response:

Just range over the images, as stated on @mkopriva comment:

{{range .ImageSlice}}{{.}}{{end}}

try on this playground

reference template docs

  • Related