mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 07:00:31 +03:00
Implement XML data support
Example: ``` {{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }} {{ range .channel.item }} <strong>{{ .title | plainify | htmlUnescape }}</strong><br /> <p>{{ .description | plainify | htmlUnescape }}</p> {{ $link := .link | plainify | htmlUnescape }} <a href="{{ $link }}">{{ $link }}</a><br /> <hr> {{ end }} {{ end }} ``` Closes #4470
This commit is contained in:
parent
58adbeef88
commit
0eaaa8fee3
12 changed files with 167 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: "transform.Unmarshal"
|
||||
description: "`transform.Unmarshal` (alias `unmarshal`) parses the input and converts it into a map or an array. Supported formats are JSON, TOML, YAML and CSV."
|
||||
description: "`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."
|
||||
date: 2018-12-23
|
||||
categories: [functions]
|
||||
menu:
|
||||
|
@ -45,3 +45,32 @@ Example:
|
|||
```go-html-template
|
||||
{{ $csv := "a;b;c" | transform.Unmarshal (dict "delimiter" ";") }}
|
||||
```
|
||||
|
||||
## 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 }}`:
|
||||
|
||||
```
|
||||
<root>
|
||||
<message>
|
||||
<title>Hugo rocks!</title>
|
||||
<description>Thanks for using Hugo</description>
|
||||
</message>
|
||||
</root>
|
||||
```
|
||||
|
||||
The following example lists the items of an RSS feed:
|
||||
|
||||
```
|
||||
{{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }}
|
||||
{{ range .channel.item }}
|
||||
<strong>{{ .title | plainify | htmlUnescape }}</strong><br />
|
||||
<p>{{ .description | plainify | htmlUnescape }}</p>
|
||||
{{ $link := .link | plainify | htmlUnescape }}
|
||||
<a href="{{ $link }}">{{ $link }}</a><br />
|
||||
<hr>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue