Templating without overwriting parent

I wanted to create a template where the baseof had this header:

<html lang="en">
    <head>
	    {{- with resources.Get "css/base_style.css" -}}
		{{- $style := . | resources.ToCSS | resources.Minify | resources.Fingerprint -}}
		<link rel="stylesheet" href="{{ $style.Permalink }}" integrity="{{ $style.Data.Integrity }}">
	    {{- else -}}
		{{ errorf "base_style.css not found" }}
	    {{- end }}
	    <link rel="dns-prefetch" href="//fonts.googleapis.com">
	    <link rel="dns-prefetch" href="//fonts.gstatic.com">
	    <link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
	    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
	    <link href="https://fonts.googleapis.com/css2?family=Arimo:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
	    <meta charset="UTF-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>{{ if .Title }}{{ .Title }} | {{ end }}{{ .Site.Title }}</title>
	    {{ block "head" . }}{{ end }}
    </head>

I define the head block that I would like to add certain files to for particular pages or different layouts on the homepage.

if I {{ define “head” }} … {{ end }} in a later template, the entire head is replaced with this new define and all the previous code is gone.

How can I add to the head without completely erasing baseof.html head content?

It sounds like the head in baseof should be permanent and outside of the define head section if you simply want to append to your existing head.

1 Like

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