Files
hugo/content/functions/readdir-and-readfile.md
T

1.0 KiB

title, linktitle, description, godocref, date, publishdate, lastmod, tags, categories, signature, workson, hugoversion, relatedfuncs, deprecated, aliases
title linktitle description godocref date publishdate lastmod tags categories signature workson hugoversion relatedfuncs deprecated aliases
readdir and readfile 2017-02-01 2017-02-01 2017-02-01
files
functions
false
/functions/readdir/
/functions/readfile/

readDir

readDir gets a directory listing from a directory relative to the current project working directory.

If your current project working directory has a single file named README.txt:

{{ range (readDir ".") }}{{ .Name }}{{ end }} → "README.txt"

readFile

Reads a file from disk and converts it into a string. Note that the filename must be relative to the current project working directory.

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!"

For more information on using readDir and readFile in your templates, see Local File Templates.