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 https://schema.org/TechArticle.

But:

I also have an about page, which should get: https://schema.org/AboutPage.

And a contact page, which should get:https://schema.org/ContactPage.

And a few pages that I want to give: https://schema.org/WebPage (other pages of my website).

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

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

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

layouts/_default/single.html

Or if you wanted to generate a JSON page:

layouts/_default/single.json.json

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

Correct.

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 }}