Search code examples
hugohugo-content-organization

How can I have a different frontmatter for my about page in Hugo?


I'm using the PaperMod theme. I have the following params in my config.yml

---
# some predefined variables
params:
  ShowReadingTime: true
  ShowShareButtons: true
  ShowBreadCrumbs: true
  ShowCodeCopyButtons: true 
---

The params work as expected for my posts. But then I have single pages (e.g. About page) that I don’t want to use the same params. I tried overriding the above values in the index.md of my /about/ directory, but it didn't work.

So I read more in the docs and blog posts about _index.md, but not sure if I figured it out right, it seems that I should do something like this instead:

config.yml // remove such params
content 
  posts
     _index.md // only add params here 
     post1.md
     post2.md
  about.md // special page that doesn't need the params

But when I do such, the params I set don’t have any effect on post1, post2.

Am I doing this the right way? I thought I can think of content/posts as a section and each section would need a _index.md for its custom front matter variables.


Solution

  • I noticed that the theme uses the {{ .Param KEY }} function to obtain the value of these custom parameters.

    The function first checks the page's parameters (front matter) then falls back to the global configuration file(s). In the global configuration file, custom parameters are specified under the params section, however, in the page's front matter, the custom parameters are specified at the root level.