How to assign schema markup (JSON) to certain pages?

How can I assign schema markup (JSON) to certain pages of my website?

I have a website with tutorials and most pages use


I also have an about page, which should get:

And a contact page, which should get:

And a few pages that I want to give: (other pages of my website).

I now have a site-schema.html file with the following lines:

{{- if .IsHome -}}
<script type="application/ld+json">
"name":"{{ }}",
"url":"{{ .Site.BaseURL }}",
"image":"{{ .Site.Params.image }}"
{{- end }}
{{- if .IsPage -}}
<script type="application/ld+json">
"name":"{{ .Title }}",
"headline":"{{ .Title }}",
"description":"{{ .Description }}",
"url":"{{ .Permalink }}",
"image":"{{ .Site.BaseURL }}{{ .Params.image }}",
"name":"{{ }}"},
"name":"{{ }}",
"url":"{{ .Site.Params.logo }}"}},
"mainEntityOfPage": {
"@id":"{{ .Permalink }}"},  
{{ if not .Date.IsZero -}}"datePublished":"{{ .Date.Format "2006-01-02" | safeHTML }}",{{- end }}
{{ with .Lastmod -}}"dateModified":"{{ .Format "2006-01-02" | safeHTML }}"{{- end }}
{{- end }}

You would add each to the appropriate template. For example, the default single page template:


Or if you wanted to generate a JSON page:


So that would mean I need to create multiple header.html files for each page type. about page, contact page, and other pages.

In my header.html file I included the following code: {{ partial "site-schema.html" . }}

Or maybe it’s just easier to not use schema markup on those pages and only on the pages that really matter. {{- if ne .Params.noschema false }}{{ partial "site-schema.html" . }}{{ end }} and then include the following line on the other pages: noschema: false


Or, if all of those pages happen to use the same template, you can have an if-statement that selects the right partial.

Do you have an example on how to use the if-statement in my case?

If you were to do it by page title, then roughly:

{{ if eq .Title "About" }}
// about partial 
{{ else if eq .Title "Contact" }}
// contact partial
{{ else }}
// default partial 
{{ end }}