Hi, everyone!
I have a task to add different head.html for homepage only (new file like head_homepage.html). My current structure of folders looks like this:
-
layouts
- _default
- baseof.html (where head.html is being used)
- about
- baseof.html
- somefolder
- baseof.html
index.html
- _default
layouts/_default/baseof.html looks something like this:
<!DOCTYPE html>
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
{{ partial "head.html" . }}
</head>
<body...>
index.html looks like:
{{ define "section1" }}
<div>...
{{ end }}
{{} define "section2" }}
<div>...
{{ end }}
I changed head.html for my new head_homepage.html in layouts/_default/baseof.html for {{ partial "head_homepage.html" . }}
, but was told it’s not a good approach, since this is kind of root folder and files that do not have baseof.html in their folders could be altered. So right now I’m trying to figure out the best approach to deal with the issue. Here the ideas I came up with:
- Using hugo detect whether we are in homepage in layouts/_default/baseof.html and use either home.html or head_homepage.html. I’m not familiar with hugo but pseudocode will look something like this:
{{ if (Site.Url eq 'homepage') }}
{{ partial "head.html" }}
{{ else }}
{{ partial "head_homepage.html" . }}
{{ end }}
- to add this section to head to layouts/index.html
<!DOCTYPE html>
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
{{ partial "head.html" . }}
</head>
<body...>
- create a baseof.html in folder layouts/baseof.html (as recommended here How can I use a different baseof.html on the homepage?)
Could you, please, help me what approach is the best or in case none of them works, recommend some other ones?
These pages didn’t help unfortunately Base Templates and Blocks | Hugo, Homepage Template | Hugo