By the end of today you can
- Read simple template expressions and trace them to content files
- Use
ifandwithto show information only when it exists - Use
rangeto display a list, while tracking what the dot means - Build an automatic Projects list, and diagnose a template error
Start from Chapter 9: both projects draft: false, a clean tree (companion branch chapter-09).
Read what you just wrote
- If this page has a non-empty description, put it in a paragraph
endcloses the block- The
<p>tags sit inside it, so nothing is left behind when it is missing - One instruction serves every page: Hugo evaluates it per page
Descriptions appear where they exist, and pages without them still render normally.
Conditions and pipes
if .Descriptionchecks;{{ .Description }}prints- Empty text, an empty list, and
falseall count as false
<a href="{{ "about/" | relURL }}">about this notebook</a>"about/"is a value,relURLa function- The pipe
|passes the left value to the right function - The result includes
/my-knowledge-site/about/: keep the input without a leading slash
Present is not correct
- The notebook shows
Status: in-progress; the reading listStatus: planned - Pages without a status show nothing, not an empty label
- The status block starts after the description’s
end, where the dot is the page
The condition proves a value exists. It does not prove it is one of our agreed values, or that it is true.
Only on the Projects page
{{ if and .IsSection (eq .Section "projects") }}.IsSection: is this a section page?eq .Section "projects": is its sectionprojects?and: both must be true; the parentheses group theeqcheck
A project page is not a section; Articles is a section with another name. Nested project sections later? Revisit this condition.
Choose, order, and link
.RegularPages: the pages directly in this section, not deeper.ByTitle: sorted by title, not by folder orderelse: what to show when the collection is empty.RelPermalink: the page’s own address, with the project prefix
/my-knowledge-site/projects/reading-list/Never assemble a URL from the title or add the repository name by hand.
Remove the duplicate list
Projects may now show two lists. In content/projects/_index.md, keep only:
---
title: "Projects"
draft: false
---
Small projects I am developing, with notes about their purpose and progress.One heading, one list, descriptions from the project pages. Check the list is not on About, Articles, or Resources.
Make sure the list responds
- Change the reading list’s
description: the page and the list change. Restore it - Set both projects to
draft: true, run plainhugo server, and open Projects: “No projects to display yet.” Restore both
Check the landing page, not old project URLs: old output can remain.
Projects now draws its titles, descriptions, and links from the project pages.
Try it yourself
Add each project’s status to its entry in the automatic list:
- Start from the status block you wrote earlier
- Place it inside the
range, after the description’send - Predict what the dot means there before you type
Expect in-progress and planned. A repeated “Projects” or a context error? Check the placement, not the content.
Optional: ask an agent to explain
Read-only, as in Chapter 8. Ask it to explain:
- The condition that selects the landing page
- The collection and its sort order
- The source of each link
- What the dot means inside
rangeandwith
It should trace the values, not just say the template looks correct. It must not claim builds or browser checks it did not run.
Save the checkpoint
hugo --minify --panicOnWarning
git status
git diff
git add layouts/all.html content/projects/_index.md
git diff --cached
git commit -m "Display project metadata and generate the Projects list"Only these two files. The description, tools, and draft experiments must leave no change in the project pages.
When something goes wrong
| What you see | What to check |
|---|---|
| A field prints nothing | The key, its spelling, and the context |
| An error mentions a string | A with or range changed the dot to text |
| Unexpected end of template | Match every block with its end |
| The list appears twice | Remove the manual list from the Markdown |
| A list link lacks the prefix | Use .RelPermalink |
Completion check
- I can trace description, status, and tools to their source values
- Missing values leave no empty labels or lists
- I can explain how
if,with, andrangediffer - I know what the dot means inside each nested block
- Projects has one automatic list with working links
- I tested the empty list and restored both projects
- I repaired the context error and added status to the list
- I committed only the two intended files