Debian Codegraph @

docs/content/en/functions/os/ReadFile.md

raw
1 ---
2 title: os.ReadFile
3 description: Returns the contents of a file.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [readFile]
9 returnType: string
10 signatures: [os.ReadFile PATH]
11 aliases: [/functions/readfile]
12 ---
13
14 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`][]. A leading path separator (`/`) is optional.
15
16 With a file named README.md in the root of your project directory:
17
18 ```md
19 This is **bold** text.
20 ```
21
22 This template code:
23
24 ```go-html-template
25 {{ readFile "README.md" }}
26 ```
27
28 Produces:
29
30 ```html
31 This is **bold** text.
32 ```
33
34 Note that `os.ReadFile` returns raw (uninterpreted) content.
35
36 [`contentDir`]: /configuration/all/#contentdir