However, both the title and tagline parameter are not outputted. I searched the forum and looked through the documentation, and this page suggests the params configuration is correct while this page says the use of Site.Params is correct also.
So in a template for a page there are two sets of params, Site’s and Page’s:
{{ .Site.Params.Tagline }}
{{ .Params.Tagline }}
The above constructions kind of depends on the context, but the last one is params defined in the page’s front matter.
As I said earlier, what’s wrong in your case is hard to say without the full picture. It could be that your TOML file contains none-map types after the params (according to the spec, only a map can follow a map) … But that is a wild guess.
Lower case parameters did indeed work. But today, after a fresh start of Hugo the regular params (.Site.Params.Title and .Site.Params.Tagline) also work. I guess there was an old file in the /public/ that wasn’t rebuild/purged when working with Hugo yesterday (or I made a beginners mistake somewhere else that I don’t recall).
So it works correctly now. Thanks for responding Josh and Bep.
OK, I will not tag you in future. But can you please explain why the params needs to be lower case in config.toml but the convention is to refer it using camel case in all the examples that I have seen?
The Camel casing is a feature of Go. Variables that start with an uppercase letter are “public” or “exported.” You can only access exported fields and methods from templates.
I am trying to understand this but am confused because params needs to be all lowercase in config.toml.
From some more testing, here are the different outcomes:
params in config.toml
[params]
foo = "bar"
This gets accessed by .Site.Params.foo.
This does not get accessed by .Site.Params.Foo. That’s expected for the Foo portion because of case sensitivity. But why is is that we need Params to access params?
If variables need to start with uppercase to be made “public”, why do we need to make params lowercase.
Params in config.toml (invalid!)
[Params]
foo = "bar"
On the other hand,
This does not get accessed by .Site.Params.foo. Even though the cases for both Params and foo match with that in the config.toml. This feels very counter-intuitive in general and also in relation to:
Variables that start with an uppercase letter are “public” or “exported.”
Params IS uppercase in config.toml and still it cannot be accessed in the templates.
My observation is as follows:
The TOML table names (params here for example) are always lowercase. Is that a rule?
The .Site keys are named inconsistently (probably not?).
Some are all lowercase: archetypedir, config, …
Some are lower camel case: defaultLayout, disableLiveReload, …
Some are upper camel case: DefaultContentLanguage, DefaultContentLanguageInSubdir.
Do these differences in cases signify anything special about these 3 categories of variables? Or did that just happen by chance?
Usually always the key names in params table are in upper camel case. So that seems to be the convention for keys or variables that are directly not under .Site, but are in .Site.Params.
If there are a few set of rules for these casing, can that please be added to the docs?
Does that mean than the keys are forced to lower case inside site.go and that is used to fetch data from toml parsed database?
I could be totally shooting in the wrong direction here, please forgive my go ignorance.
Update: Actually scratch that. That code probably deals with the keys inside [params].
But I believe somewhere else, what I explain below is happening. I am still trying to understand/grep where that is happening.
Basically, from what I understood, the [params] is stored as .Site.Params in go as you want that object to be public. But then it should not impose the limitation on the config.toml to have that as all lowercase [params].
So somewhere, when .Site.Params is seen in the user template, the code looks for something like “ToLower(Params)” inside the toml database. Again, toml is case sensitive. So if that code in hugo used something like “ToLower”, the toml database has to have [params], and so [Params] will not do. But why is that needed? Can’t hugo treat [Params] or [params] as the same thing?
This is what’s creating this apparent inconsistency from the view point of a first time go and toml user.
Here is how I interpret the rules for naming stuff in config.toml and using them in templates:
Rules for naming variables in config.toml and accessing them in templates
Custom variables or table names are not allowed directly inside config.toml.
You can only use the inbuilt variables outside TOML tables… like title or supported table names like params.
If you want to use custom variables for theme configuration, etc, put them inside params table. These variables can be named as per user’s liking, in any letter case. But they have to be referenced with the exact case inside the templates.
If table params has Abc key or variable, it has to be referenced as .Site.Params.Abc.
If table params has aBc key or variable, it has to be referenced as .Site.Params.aBc.
Direct variables or TOML table names in config.tomlmust be all lower case.
If the variable is title, it has to be referenced in UpperCamelCase inside the templates with the .Site. prefix, like .Site.Title.
If the table name is params, it has to be referenced in UpperCamelCase inside the templates with the .Site. prefix, like .Site.Params.
Test case to try out various combinations of cases for keys and tables.
That said, this project is ready-to-run. So you can also git clone it and hugo to see it in action and play with commenting/uncommenting different things in the test case.
My earlier letter case inconsistency research was for a separate issue. What you posted used to work when I posted that example project. But now that is failing as well. I confirm that failure too. Looks like some recent changes (2-3 days) made in the hugo master caused this.
@bep I hope I am tagging you for the right cause this time. Looks like the recent ToLowerMap changes are causing this.
My site builds correctly on version 0.17 but fails on the latest hugo build (as of now) with these errors:
Started building sites ...
ERROR: 2016/10/17 10:38:29 general.go:236: theme/_default/summary.html is an incomplete or empty template
ERROR: 2016/10/17 10:38:29 general.go:236: theme/_default/li.html is an incomplete or empty template
ERROR: 2016/10/17 10:38:29 general.go:236: Error while rendering page post/generating-a-transparent-favicon.md: template: /home/kmodi/hugo/kaushalmodi.gitlab.io/themes/lanyon/layouts/_default/baseof.html:5:49: executing "main" at <.Site.Params.DateFor...>: invalid value; expected string
ERROR: 2016/10/17 10:38:29 general.go:236: Error while rendering page post/how-i-created-this-blog.md: template: /home/kmodi/hugo/kaushalmodi.gitlab.io/themes/lanyon/layouts/_default/baseof.html:5:49: executing "main" at <.Site.Params.DateFor...>: invalid value; expected string
ERROR: 2016/10/17 10:38:29 general.go:236: Error while rendering page post/elisp-meta-characters-in-string.md: template: /home/kmodi/hugo/kaushalmodi.gitlab.io/themes/lanyon/layouts/_default/baseof.html:5:49: executing "main" at <.Site.Params.DateFor...>: invalid value; expected string