Remarshal.md - hugo - [fork] hugo port for 9front
(HTM) git clone https://git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
Remarshal.md (1746B)
---
1 ---
2 title: transform.Remarshal
3 description: Marshals a string of serialized data, or a map, into a string of serialized data in the specified format.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: []
9 returnType: string
10 signatures: [transform.Remarshal FORMAT INPUT]
11 aliases: [/functions/transform.remarshal]
12 ---
13
14 The format must be one of `json`, `toml`, `yaml`, or `xml`. If the input is a string of serialized data, it must be valid JSON, TOML, YAML, or XML.
15
16 > [!note]
17 > This function is primarily a helper for Hugo's documentation, used to convert configuration and front matter examples to JSON, TOML, and YAML.
18 >
19 > This is not a general purpose converter, and may change without notice if required for Hugo's documentation site.
20
21 Example 1
22 : Convert a string of TOML to JSON.
23
24 ```go-html-template
25 {{ $s := `
26 baseURL = 'https://example.org/'
27 languageCode = 'en-US'
28 title = 'ABC Widgets'
29 `}}
30 <pre>{{ transform.Remarshal "json" $s }}</pre>
31 ```
32
33 Resulting HTML:
34
35 ```html
36 <pre>{
37 "baseURL": "https://example.org/",
38 "languageCode": "en-US",
39 "title": "ABC Widgets"
40 }
41 </pre>
42 ```
43
44 Rendered in browser:
45
46 ```text
47 {
48 "baseURL": "https://example.org/",
49 "languageCode": "en-US",
50 "title": "ABC Widgets"
51 }
52 ```
53
54 Example 2
55 : Convert a map to YAML.
56
57 ```go-html-template
58 {{ $m := dict
59 "a" "Hugo rocks!"
60 "b" (dict "question" "What is 6x7?" "answer" 42)
61 "c" (slice "foo" "bar")
62 }}
63 <pre>{{ transform.Remarshal "yaml" $m }}</pre>
64 ```
65
66 Resulting HTML:
67
68 ```html
69 <pre>a: Hugo rocks!
70 b:
71 answer: 42
72 question: What is 6x7?
73 c:
74 - foo
75 - bar
76 </pre>
77 ```
78
79 Rendered in browser:
80
81 ```text
82 a: Hugo rocks!
83 b:
84 answer: 42
85 question: What is 6x7?
86 c:
87 - foo
88 - bar
89 ```