mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	Update datafiles.md
additional example for named data values
This commit is contained in:
		
				
					committed by
					
						
						Bjørn Erik Pedersen
					
				
			
			
				
	
			
			
			
						parent
						
							d4b6f9aca3
						
					
				
				
					commit
					e96624cce8
				
			@@ -81,3 +81,24 @@ And then in `partial/artist.html`:
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Discover a new favourite bass player? Just add another TOML-file.
 | 
			
		||||
 | 
			
		||||
## Example: Accessing named values in a Data File
 | 
			
		||||
 | 
			
		||||
Assuming you have the following YAML structure to your `User0123.yml` Data File located directly in `data/`
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
Name: User0123
 | 
			
		||||
"Short Description": "He is a jolly good fellow."
 | 
			
		||||
Achievements:
 | 
			
		||||
  - "Can create a Key, Value list from Data File"
 | 
			
		||||
  - "Learns Hugo"
 | 
			
		||||
  - "Reads documentation"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
To render the `Short Description` in your `layout` File following code is required.
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
{{ $.Scratch.Set "ShortDesc" ( index $.Site.Data.User0123 "Short Description" ) }}
 | 
			
		||||
<div>Short Description of {{.Site.Data.User0123.Name}}: <p>{{ $.Scratch.Get "ShortDesc" }}</p></div>
 | 
			
		||||
{{ end }}
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user