os.ReadFile
Returns the contents of a file.
- Syntax
- os.ReadFile PATH
- Returns
- string
- Alias
- readFile
Usage
The os.ReadFile function returns the contents of the file at the given PATH. The function resolves the path relative to the root of your project directory, then relative to the root of each module. If it does not find a matching file, it resolves the path relative to the content directory of the unified file system. A leading path separator (/) is optional.
The function returns the raw content of the file without rendering it, or an empty string if the file does not exist.
Examples
These examples use a README.md file in the root of your project directory:
README.md
This is **bold** text.Reading the file:
{{ os.ReadFile "README.md" }} → This is **bold** text.Rendering the content with the transform.Markdownify function:
{{ os.ReadFile "README.md" | markdownify }} → This is <strong>bold</strong> text.Last updated:
November 8, 2026
:
content: Remove categories from front matter (1cc1dd83a)
Improve this page