Conditional statement checking for a page type?

Hello

I am currently making my first site with Hugo, loving it so far. I am attempting to apply schema mark-up which changes depending on the current type of page.

site_schema.partial

{{ if .IsHome -}}
<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "name": "{{ .Site.Title }}",
    "url": "{{ .Site.BaseURL }}",
    "description": "{{ .Site.Params.description }}",
    "thumbnailUrl": "{{ .Site.Params.Logo | absURL }}",
    "license": "{{ .Site.Params.Copyright }}"
}
</script>
{{ else if .IsPage }}
{{ $author :=  or (.Params.author) (.Site.Author.name) }}
{{ $org_name :=  .Site.Title }}
<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "BlogPosting",
    "articleSection": "{{ .Section }}",
    "name": "{{ .Title | safeJS }}",
    "headline": "{{ .Title | safeJS }}",
    "alternativeHeadline": "{{ .Params.lead }}",
    "description": "{{ if .Description }}{{ .Description | safeJS }}{{ else }}{{if .IsPage}}{{ .Summary  }}{{ end }}{{ end }}",
    "inLanguage": {{ .Site.LanguageCode | default "en-us" }},
    "isFamilyFriendly": "true",
    "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "{{ .Permalink }}"
    },
    "author" : {
        "@type": "Person",
        "name": "{{ $author }}"
    },
    "creator" : {
        "@type": "Person",
        "name": "{{ $author }}"
    },
    "accountablePerson" : {
        "@type": "Person",
        "name": "{{ $author }}"
    },
    "copyrightHolder" : "{{ $org_name }}",
    "copyrightYear" : "{{ .Date.Format "2006" }}",
    "dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
    "datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
    "dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
    "publisher":{
        "@type":"Organization",
        "name": {{ $org_name }},
        "url": {{ .Site.BaseURL }},
        "logo": {
            "@type": "ImageObject",
            "url": "{{ .Site.Params.logo | absURL }}",
            "width":"32",
            "height":"32"
        }
    },
    "image": {{ if .Params.images }}[{{ range $i, $e := .Params.images }}{{ if $i }}, {{ end }}{{ $e | absURL }}{{ end }}]{{ else}}{{.Site.Params.logo | absURL }}{{ end }},
    "url" : "{{ .Permalink }}",
    "wordCount" : "{{ .WordCount }}",
    "genre" : [ {{ range $index, $tag := .Params.tags }}{{ if $index }}, {{ end }}"{{ $tag }}" {{ end }}],
    "keywords" : [ {{ range $index, $keyword := .Params.keywords }}{{ if $index }}, {{ end }}"{{ $keyword }}" {{ end }}]
}
</script>
{{ end }}

The other type of page I have on the website is service pages which require unique schema, how would I check to see if it is a service page in a conditional statement. I looked at the taxonomies doc but ended up going around in circles with broken code.

{{ else if isset .Params “service” }} worked it out.

Have a look at how sections work in Hugo. You can target specific sections via is .Section "sectionname".

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.