2

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.

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
mfaani
  • 33,269
  • 19
  • 164
  • 293
  • I think you were right the first time. You should be able to override those params in the about page's front matter. Did you format the front matter section correctly? It does not need the `params:` section. – Richard Smith Jan 11 '22 at 08:16
  • By any chance, is your repo public ? – Sidharth R Jan 11 '22 at 11:38
  • @RichardSmith Thanks that worked! Would you mind posting that as an answer? The only one that didn't work was even when I set `ShowShareButtons: false` on the About page, I still see the share buttons at the bottom of the page. FWIW it's not exactly a footer. They just show up just below where the post ends. – mfaani Jan 11 '22 at 15:45
  • @SidharthRanasingh I'm not production ready yet. My structure is very similar to the example site. You can find it from [here](https://github.com/adityatelange/hugo-PaperMod/tree/exampleSite). The author created this. Just notice that the example site is on `exampleSite` _branch_. – mfaani Jan 11 '22 at 16:31

2 Answers2

2

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.

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
Richard Smith
  • 45,711
  • 6
  • 82
  • 81
  • "however, in the page's front matter, the custom parameters are specified at the root level." This is correct. But I couldn't find docs from the links. Did anything lead you to conclude that? – mfaani Jan 12 '22 at 00:22
  • 1
    That's how I interpreted this statement: "Any other value defined in the front matter in a content file, including taxonomies, will be made available as part of the .Params variable." - which is also confirmed by the [example on the page](https://gohugo.io/variables/page/#page-level-params). – Richard Smith Jan 12 '22 at 08:03
0

I would set them in the config to make them site-wide variables. Then I would set different params in the page and overwrite with the logic below.

Referring to site-wide variables:

.Site.Params.yourparamkey

Referring to a page variable:

.Params.yourparamkey

Checking which one to use:

{{- if .Params.yourparamkey -}}
  {{- $yourparamkey := .Params.yourparamkey -}}
{{- else -}}
  {{- $yourparamkey := .Site.Params.yourparamkey -}}
{{- endif -}}

Using your param key:

{{ $yourparamkey }}
Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60