.Params not working in home.md?


I have my homepage at content/home.md with template at layouts/index.html

When I create a custom param in TOML, ex.:

title: "Home"
intro: "Welcome to my little place on the internet"

and try to use {{ .Params.intro }}, it shows empty on page (no error though)

Documentation states it should just work. What am I doing wrong?

Repo: https://github.com/patrykkalinowski/homepage



Please review Requesting Help and share your code. Then we can figure it out. :slight_smile:


Here it is: https://github.com/patrykkalinowski/homepage

Updated original post, too.



content/home renders at baseURL/home/ and by default would use your single.html layout. So, if you were to put {{.Params.intro}} somewhere in your single.html and navigate to /home, you will see it working then.

In your layouts/index.html, it is this bit that grabs the contents of content/home.md:

{{ range where .Data.Pages "Title" "Home" }}
    <div class="markdown">
    {{ .Content }}
{{ end }}

If you were to put {{ .Params.intro }} inside the range there, it would show up as well, because you would then be in the context of the home.md Page.

So, your options:

Grab the home context then get .Params.intro:

{{ (.Site.GetPage "/home").Params.intro }}

Or have a content/_index.md and basically use that to populate your layouts/index.html instead of home.md. With this you can grab .Params.intro directly, and also avoid the whole range-ing above to get your .Content and again just get it directly. Unless you really need a /home page, in which case option 1 is for you.


Thank you pointyfar, works now :slight_smile: I will look into switching to _index.md, it sounds more reasonable