Here’s another example that works nicely for creating entirely data-driven hugo sites.
Inside the data/person/demo.toml
file we have a basic example person:
first = "Demo"
last = "Person"
pubname = "Demo"
github = "youraccount"
Then in layouts/student/block.html
view template, (which I use to include in the _default/single.html
template):
{{ with (index .Site.Data.person (substr $.File.LogicalName 0 -3)) }}
<div class="student">
<div class="student__pubname">{{ .pubname }}</div>
</div>
{{ end }}
Notice that the date is a logical person
and the template is for a student
type. This is because in the larger application I only have person
logical data types and cast them to roles and views using this method of type views and content, which brings us to the content/student/demo.md
file. It’s empty. Just add it. This is because as far as I know, Hugo doesn’t actually create any single page unless there is a corresponding content file of some kind. At first this seems annoying, but turns out it is not that bad and allows you to turn on or off a page simple by removing or touching the content file.