mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
6efb279bfa
a9584e3d1 ci: bump GitHub workflow actions to latest versions f37ee374d Fix methods related to time.After a49214057 Correct heading render hook example 4b696f936 Update README.md b5a6e4039 Clean up the contributing section a5d79ed19 Fixed typo: instea → instead 6150a60e3 Remove the "local file templates" page 9395743dc Update/vendor theme 33d8c10cc Remove output format "name" parameter 7200ad97d Add security section to resources.GetRemote page 3f1e056b2 Remove erroneous front matter field 07c9a7e42 Add alpha index to glossary 6619c8aa0 Fix Page.Params example 145a92359 Simplify string concat example in math.Add 42488bb09 Add string concat example to math.Add eb20521a2 Fix flash of unstyled content with mathematical markup 74603bebe Fix typo in 'typesetting' git-subtree-dir: docs git-subtree-split: a9584e3d146c4a194d937a4dc8a37cde5ba1c618
38 lines
912 B
Markdown
38 lines
912 B
Markdown
---
|
|
title: os.ReadFile
|
|
description: Returns the contents of a file.
|
|
categories: []
|
|
keywords: []
|
|
action:
|
|
aliases: [readFile]
|
|
related:
|
|
- functions/os/FileExists
|
|
- functions/os/Getenv
|
|
- functions/os/ReadDir
|
|
- functions/os/Stat
|
|
returnType: string
|
|
signatures: [os.ReadFile PATH]
|
|
aliases: [/functions/readfile]
|
|
---
|
|
|
|
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`](/getting-started/configuration#contentdir). A leading path separator (`/`) is optional.
|
|
|
|
With a file named README.md in the root of your project directory:
|
|
|
|
```text
|
|
This is **bold** text.
|
|
```
|
|
|
|
This template code:
|
|
|
|
```go-html-template
|
|
{{ readFile "README.md" }}
|
|
```
|
|
|
|
Produces:
|
|
|
|
```html
|
|
This is **bold** text.
|
|
```
|
|
|
|
Note that `os.ReadFile` returns raw (uninterpreted) content.
|