How can obtain correct string in ?
I want “image” in partial markup-article-html but this:
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Article",
{{ with .Page.Title }} "name" : "{{ . }}", {{ end }}
{{ if .Page.Params.featured_image }}
{{- $img := (printf "%s%s" .Page.Permalink .Page.Params.featured_image) | string -}}
"image" : "{{ $img -}}", {{- end }}
"image" : "{{- .Page.Permalink -}}{{- .Page.Params.featured_image -}}",
"image" : "https://test/test.webp",
render as
"image" : "http:\/\/192.168.12.79:1313\/iscrizione\/logo-il-mosaico.webp",
"image" : "http:\/\/192.168.12.79:1313\/iscrizione\/logo-il-mosaico-danza-asd-culturale.webp",
"image" : "https://test/test.webp",
First two render wrong, test is OK. How to obtain correct string?
Thanks.
Unless I’m missing something, the first two are not wrong. The slashes are simply escaped.
@jmooring Yes, but i need unescaped string in page. How to do this?
bep
4
I suspect you will get a much easier life making jsonify
handle the JSON encoding:
{{ $mainEntityOfPage := dict "@type" "WebPage" "@id" .Permalink }}
{{ $schema := dict
"@context" "https://schema.org"
"@type" "NewsArticle"
"mainEntityOfPage" $mainEntityOfPage
"headline" .Title
"image" $img.Permalink
"datePublished" .PublishDate
"dateModified" .Lastmod
}}
{{ $script := printf `<script type="application/ld+json">%s%s%s</script>` "\n\t" ($schema | jsonify ) "\n" }}
{{ $script | safeHTML }}
2 Likes
@bep thank you very much for your help. Pointing me on right direction to obtain complete code I need and showing much things 
Share my actual markup-article.html:
{{ $img := (printf "%s%s" .Page.Permalink .Page.Params.featured_image) | string }}
{{ $author := dict "@type" "Person" "name" .Page.Params.Author "givenName" .Page.Params.Author "url" "https://example.org" }}
{{ $mainEntityOfPage := dict "@type" "WebPage" "@id" .Permalink }}
{{ $schema := dict
"@context" "https://schema.org"
"@type" "Article"
"mainEntityOfPage" $mainEntityOfPage
"headline" .Title
"image" $img
"datePublished" .PublishDate
"dateModified" .Lastmod
"author" $author
}}
{{ $script := printf `<script type="application/ld+json">%s%s%s</script>` "\n\t" ($schema | jsonify ) "\n" }}
{{ $script | safeHTML }}
1 Like
system
Closed
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.