Merge commit '346b60358dd8ec2ca228e6635bff9d7914b398b7'

This commit is contained in:
Bjørn Erik Pedersen
2025-01-23 09:47:46 +01:00
384 changed files with 3305 additions and 3271 deletions

View File

@@ -13,17 +13,17 @@ action:
signatures: [SITE.Data]
---
Use the `Data` method on a `Site` object to access data within the data directory, or within any directory [mounted] to the data directory. Supported data formats include JSON, TOML, YAML, and XML.
Use the `Data` method on a `Site` object to access data within the `data` directory, or within any directory [mounted] to the `data` directory. Supported data formats include JSON, TOML, YAML, and XML.
[mounted]: /hugo-modules/configuration/#module-configuration-mounts
{{% note %}}
Although Hugo can unmarshal CSV files with the [`transform.Unmarshal`] function, do not place CSV files in the data directory. You cannot access data within CSV files using this method.
Although Hugo can unmarshal CSV files with the [`transform.Unmarshal`] function, do not place CSV files in the `data` directory. You cannot access data within CSV files using this method.
[`transform.Unmarshal`]: /functions/transform/unmarshal/
{{% /note %}}
Consider this data directory:
Consider this `data` directory:
```text
data/
@@ -55,7 +55,7 @@ And these data files:
isbn: 978-0521280495
{{< /code >}}
Access the data by [chaining] the [identifiers]:
Access the data by [chaining](g) the [identifiers](g):
```go-html-template
{{ range $category, $books := .Site.Data.books }}
@@ -101,14 +101,10 @@ To find a fiction book by ISBN:
{{ end }}
```
In the template examples above, each of the keys is a valid [identifier]. For example, none of the keys contains a hyphen. To access a key that is not a valid identifier, use the [`index`] function. For example:
[identifier]: /getting-started/glossary/#identifier
In the template examples above, each of the keys is a valid identifier. For example, none of the keys contains a hyphen. To access a key that is not a valid identifier, use the [`index`] function. For example:
```go-html-template
{{ index .Site.Data.books "historical-fiction" }}
```
[`index`]: /functions/collections/indexfunction/
[chaining]: /getting-started/glossary/#chain
[identifiers]: /getting-started/glossary/#identifier