Skip to content

Instantly share code, notes, and snippets.

@budparr
Last active September 12, 2017 00:30
Show Gist options
  • Save budparr/9b679750a522b1f757c7fa27af00dc34 to your computer and use it in GitHub Desktop.
Save budparr/9b679750a522b1f757c7fa27af00dc34 to your computer and use it in GitHub Desktop.
#gohugoio
{{/* Set header classes (e.g. colors scheme) at either the global, section, or page level */}}
{{/* Initially set $.Param "headerClasses" at the page or global (config) level, with a default if neither exist */}}
{{ $headerClasses := $.Param "headerClasses" | default "bg-near-black silver"}}
{{/* To set at the section level, get the section the current page belongs to */}}
{{ $section := .Site.GetPage "section" .Section }}
{{/* If the page belongs to a section, */}}
{{ if $section}}
{{/* get the section's headerClasses param value, defaulting to the global/page level. */}}
{{ $headerClasses := $section.Param "headerClasses" | default $headerClasses }}
{{/* Set the colors based on the page's setting, but if there isn't one, look to the section's settings above */}}
{{ $headerClasses := .Params.headerClasses | default $headerClasses }}
{{/* Add to Scratch so we can access it outside of the conditional */}}
{{ $.Scratch.Add "headerClasses" $headerClasses }}
{{ end }}
{{/* Define the variable based on what's in Scratch, and if nothing there, get the first default values */}}
{{ $headerClasses := $.Scratch.Get "headerClasses" | default $headerClasses }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment