mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit '83bef6955e014d40c0f00db9cebe09113154e999'
This commit is contained in:
33
docs/content/en/functions/readfile.md
Normal file
33
docs/content/en/functions/readfile.md
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: readFile
|
||||
description: Reads a file from disk relative to the current project working directory and returns a string.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-04-30
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [files]
|
||||
signature: ["readFile PATH"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: [readDir]
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
Note that the filename must be relative to the current project working directory, or the project's `/content` folder.
|
||||
|
||||
So, if you have a file with the name `README.txt` in the root of your project with the content `Hugo Rocks!`:
|
||||
|
||||
```
|
||||
{{readFile "README.txt"}} → "Hugo Rocks!"
|
||||
```
|
||||
|
||||
If you receive a "file doesn't exist" error with a path listed, do take note that the path is the last one checked by the function, and may not accurately reflect your target. You should generally double-check your path for mistakes.
|
||||
|
||||
For more information on using `readDir` and `readFile` in your templates, see [Local File Templates][local].
|
||||
|
||||
[local]: /templates/files/
|
Reference in New Issue
Block a user