{{/* Function to inject custom code into layouts without overriding files. */}}
{{/* Input: hook folder name (str) */}}
{{/* Output: loaded (bool) */}}

{{ $loaded := false }}
{{ $partial_dir := printf "hooks/%s/" .hook }}
{{ $context := .context }}
{{ $hook_dir_path := path.Join "layouts/_partials" $partial_dir }}
{{ with try (os.ReadDir $hook_dir_path) }}
  {{ with .Value }}
    {{ range . }}
      {{ if not .IsDir }}
        {{ $partial_path := path.Join $partial_dir .Name }}
        {{ partial $partial_path $context }}
        {{ $loaded = true }}
      {{ end }}
    {{ end }}
  {{ end }}
{{ end }}
{{/* The return statement below is for debug purposes only and prevents the above partial(s) being included in the page */}}
{{/* return $loaded */}}
