No. Additionally, if you install Hugo on Linux with the snap package, globally installed npm packages will fail. As an aside, I wouldn’t use the snap package as it stands today. It has issues.
Content View templates are easier to use in some situations. Example:
content
├── employees/
│ ├── john-smith/
│ │ ├── index.md
│ │ └── portrait.jpg
│ └── tricia-rogers/
│ ├── index.md
│ └── portrait.jpg
├── products/
│ ├── product-1.md
│ └── product-2.md
└── _index.md
Let’s say we want to:
- Use the same template to list both employees and products
- Display the title, summary, and a photograph when listing employees
- Display the title and summary (no photograph) when listing products
layouts/_default/list.html
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ range .Pages }}
{{ .Render "summary" }}
{{ end }}
{{ end }}
The .Render method is aware of the Content Type it is rendering. So we can structure our layout directory like this:
layouts/
├── _default/
│ ├── baseof.html
│ ├── home.html
│ ├── list.html
│ └── single.html
├── employees/
│ └── summary.html
└── products/
└── summary.html
layouts/employees/summary.html
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ with .Resources.GetMatch "portrait.jpg" }}
{{ $i := .Resize "120x webp" }}
<img src="{{ $i.RelPermalink }}" alt="{{ $i.Title }}" width="{{ $i.Width }}" height="{{ $i.Height }}">
{{ end }}
<div>{{ .Summary }}</div>
layouts/products/summary.html
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
<div>{{ .Summary }}</div>
You could accomplish the same thing using conditionals, but it is not as clean:
Details...
layouts/
└── _default/
├── baseof.html
├── home.html
├── list.html
└── single.html
layouts/_default/list.html
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ range .Pages }}
{{ if eq .Type "employees" }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ with .Resources.GetMatch "portrait.jpg" }}
{{ $i := .Resize "120x webp" }}
<img src="{{ $i.RelPermalink }}" alt="{{ $i.Title }}" width="{{ $i.Width }}" height="{{ $i.Height }}">
{{ end }}
<div>{{ .Summary }}</div>
{{ end }}
{{ if eq .Type "products" }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
<div>{{ .Summary }}</div>
{{ end }}
{{ end }}
{{ end }}
You could accomplish the same thing using partials, but again, it is not as clean:
Details...
layouts/
├── _default/
│ ├── baseof.html
│ ├── home.html
│ ├── list.html
│ └── single.html
└── partials/
├── employees/
│ └── summary.html
└── products/
└── summary.html
layouts/_default/list.html
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ range .Pages }}
{{ partial (printf "%s/summary" .Type) . }}
{{ end }}
{{ end }}
A couple of other differences between Content View templates and partials:
-
When you call a template with .Render it receives the current context. When you call a template with partial you can pass whatever you want. Example:
{{ partial (printf "%s/summary" .Type) (dict "page" . "myvar" 42) }}
-
A partial can return a value, allowing you to create your own functions. Example:
layouts/partials/functions/sum.html
{{ $total := 0 }}
{{ range . }}
{{ $total = add $total .}}
{{ end }}
{{ return $total }}
Then call it with:
{{ partial "functions/sum" (slice 1 2 3 4 5) }} --> 15