hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

readfile.md (1103B)

    1 ---
    2 title: readFile
    3 description: Returns the contents of a file.
    4 date: 2017-02-01
    5 publishdate: 2017-02-01
    6 lastmod: 2021-11-26
    7 categories: [functions]
    8 menu:
    9   docs:
   10     parent: "functions"
   11 keywords: [files]
   12 signature: ["os.ReadFile PATH", "readFile PATH"]
   13 workson: []
   14 hugoversion:
   15 relatedfuncs: ['os.FileExists','os.ReadDir','os.Stat']
   16 deprecated: false
   17 aliases: []
   18 ---
   19 The `os.ReadFile` function attempts to resolve the path relative to the root of your project directory. If a matching file is not found, it will attempt to resolve the path relative to the [`contentDir`]({{< relref "getting-started/configuration#contentdir">}}). A leading path separator (`/`) is optional.
   20 
   21 With a file named README.md in the root of your project directory:
   22 
   23 ```text
   24 This is **bold** text.
   25 ```
   26 
   27 This template code:
   28 
   29 ```go-html-template
   30 {{ os.ReadFile "README.md" }}
   31 ```
   32 
   33 Produces:
   34 
   35 ```html
   36 This is **bold** text.
   37 ```
   38 
   39 Note that `os.ReadFile` returns raw (uninterpreted) content.
   40 
   41 For more information on using `readDir` and `readFile` in your templates, see [Local File Templates]({{< relref "/templates/files" >}}).