hugo/content/functions/readfile.md
Bjørn Erik Pedersen d2ec1a06df Squashed 'docs/' changes from f9a5dc59b..76e881257
76e881257 Improve .Scratch entry (#454)
37ed09702 Remove zero-byte .gitmodules file altogether
943f21619 Add a note about valid values for taxonomies in front-matter
ebcfa30d7 Update definition list formatting
46050042a Corrected formatting
87c539101 Updated readFile documentation
8fd130395 commands: Regenerate the CLI docs
6ce0ce8d6 data: Regenereate the docshelper
9fe78fabd Release 0.39
33039c6ba releaser: Prepare repository for 0.40-DEV
e3a780907 releaser: Add release notes to /docs for release of 0.39
54406e3fa releaser: Bump versions for release of 0.39
21017660b Merge commit '047c4188dfc854f658d16f1e4a9501f9c97a31c7'

git-subtree-dir: docs
git-subtree-split: 76e88125760c140541edab2061aed31c6db2d800
2018-04-21 23:01:55 +02:00

1 KiB

title description godocref date publishdate lastmod categories menu keywords signature workson hugoversion relatedfuncs deprecated aliases
readFile Reads a file from disk relative to the current project working directory and returns a string. 2017-02-01 2017-02-01 2017-04-30
functions
docs
parent
functions
files
readFile PATH
readDir
false

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.