lot of ideas here! I’m going to answer all of them best I can, but nothing I say here is the definitive “best” prescriptive solution for you, it sounds like you got some more complex data structures and considerations so it’s up to you to find the best fit for you. So I’m trying to give you some ideas and options and roughly how you would go about doing it in Hugo, but you’ll have to use this as a starting point to see what works for you. In other words, don’t expect anything I write here just to work by magic after a copy paste!
So starting from the bottom of your questions up:
If you do this:
{{ with .Params }}
...
{{ partial "config.html" $ }}
...
{{ end }}
Then you can have:
{{/* this is in config.html */}}
<p>my front matter field is: {{ .Params.myfieldname}}</p>
<p>Item 1 price is: {{ .Site.Data.price.itemname1}}</p>
next question up:
The problem can be solved either by this way, or by sourcing both specific and global parts from /data/price.yml - which may be possible if I find a way to use content filename (like i7-5500U.md) to pick its price from /data/price.yml.
You could use a where
to pick something from your data file - see help here collections.Where | Hugo. You could even do this using the filename, or you could compare against a front-matter field.
{{ $name := .File.ContentBaseName }}
{{/* alternatively, pick your itemname from front-matter */}}
{{ $name := .Params.itemname }}
<p>this is item {{ $name }}</p>
{{ range where .Site.Data.prices "name" "==" $name }}
<p>the price is: {{ .price }}</p>
{{ end }}
For this to work, your ./data/prices.yaml
file would need to look something like this:
- name: item1
price: 123.45
- name: item2
price: 678.90
next question:
{{ $prices := .page.Site.Data.prices }}
What is it used for, where and how I can use it?
This is what would go in your partial file config.html. This actually answers your other questions:
…lets me quote some key - value pairs from some dictionary. But where is it?. . .And what are “page” and “params” here?
“page” and “params” are just arbitrary names you give to the parameters you pass to your partial inside the dict. You access them using these names. I just picked them because they’re descriptive. So when you’re in your partial, you access them using these names, e.g to access a param in your partial you go .params.myfieldnamehere
or to access the page level you go .page.[PageLevelAnythingGoHere]