I have read trough Configure Hugo
So I have a config file socialnetworks.toml
in the folder ./config/_default
with the following content
[github]
name = "GitHub"
baseURL = "https://github.com/"
icon = "fab fa-github"
[gitlab]
name = "GitLab"
baseURL = "https://gitlab.com/"
icon = "fab fa-gitlab"
And I want to use this as follows:
{{ range $value := .Site.Params.Socialnetworks }}
<p>{{ $value }}</p>
{{ end -}}
Which results in no output. There are no errors en the console tough.
Have you defined these parameters within the [params]
table?
Params are entered either within a [params]
table like so:
[Params]
foo = "bar"
Or in a params.toml
Otherwise .Site.Params
will return empty (or throw an error).
See: Configure Hugo | Hugo
You cannot have a custom file. You need to nest it under params.toml
: Configure Hugo | Hugo
Each file represents a configuration root object, such as params.toml
for [Params]
, menu(s).toml
for [Menu]
, languages.toml
for [Languages]
etc…
Ahh ok I thought I can do it the same way as the language.toml
but apparently, this is a special file then. So my params.toml
would look like this
....
[socialnetworks]
[[docker]]
name = "Docker"
baseURL = "https://hub.docker.com/u/"
icon = "fab fa-docker"
I tried but
<div>
<p>Socialnetworks:</p>
{{ range $value := .Site.Params.Socialnetworks }}
<p>{{ $value }}</p>
{{ end -}}
</div>
Shows nothing, even after I restarted HUGO:
Difficult to say without seeing the rest of your code. Some ideas:
- use lowercase keys
- make sure you are in the correct context; the “dot” is different inside a
with
block, for example.
Beyond that we have to see what your code looks like.
ju52
8
check TOML syntax
https://toml.io/en/v1.0.0#table
try
[Params]
[[socialnetworks]]
name = "Docker"
baseURL = "https://hub.docker.com/u/"
icon = "fab fa-docker"
[[socialnetworks]]
name = "Twitter"
...
<div>
<p>Socialnetworks:</p>
{{ range .Site.Params.socialnetworks }}
<p>{{ .name }}</p>
{{ end -}}
</div>
@pointyfar
I use this: GitHub - h-enk/doks: Hugo theme helping you build modern documentation websites. and extend the docs-toc.html as follows - just for testing purposes
{{ if ne .Params.toc false -}}
<div class="page-links">
<h3>On this page</h3>
{{ .TableOfContents }}
</div>
{{ end -}}
{{ if .IsTranslated }}
<div class="page-links">
<h3>{{ i18n "translations" }}</h3>
{{ partial "sidebar/lang-switcher.html" . }}
</div>
{{ end -}}
<div>
<p>Socialnetworks:</p>
{{ range $value := .Site.Params.Socialnetworks }}
<p>{{ $value }}</p>
{{ end -}}
</div>
I use the config.toml
as given and add my stuff as shown in my previous answer.
Ok so I defined this in the params.toml
[[socialnetworks]]
[[socialnetworks.docker]]
name = "Docker"
baseURL = "https://hub.docker.com/u/"
and I get the expected output
Thanks a lot @ju52 and @pointyfar I guess I understand the concept now
system
Closed
11
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.