Hugo Shortcodes Library
GitHubToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

Read File Contents

A Hugo shortcode to read in the contents of any file in your source repo. Fun fact, created because of this repo! I wanted a way to showcase the shortcodes on the page, but not worry about the displayed content and the actual shortcode getting out of sync!

How to use

# file.md
{{< read_file_contents path="/layouts/shortcodes/read_file_contents.html" >}}

Shortcode


{{ with .Get "path" }}
{{ os.ReadFile . }}
{{ end}}

Sample

Using {{< read_file_contents path="/Makefile" >}}.

# Makefile

build:
	hugo --gc --minify

serve:
	hugo server -D -b localhost:1111 --port 1111