transform.Unmarshal
少于1分钟
将以下英文翻译为中文:
transform.Unmarshal
https://gohugo.io/functions/transform.unmarshal/
transform.Unmarshal (alias unmarshal) parses the input and converts it into a map or an array. Supported formats are JSON, TOML, YAML, XML and CSV.
语法
RESOURCE or STRING | transform.Unmarshal [OPTIONS]
The function accepts either a Resource created in Hugo Pipes or via Page Bundles, or simply a string. The two examples below will produce the same map:
| |
In both the above examples, you get a map you can work with:
| |
The above prints Hello Hugo.
CSV Options
Unmarshal with CSV as input has some options you can set:
delimiter
The delimiter used, default is
,.comment
The comment character used in the CSV. If set, lines beginning with the comment character without preceding whitespace are ignored.:
Example:
| |
XML data
As a convenience, Hugo allows you to access XML data in the same way that you access JSON, TOML, and YAML: you do not need to specify the root node when accessing the data.
To get the contents of <title> in the document below, you use {{ .message.title }}:
| |
The following example lists the items of an RSS feed:
| |