Hugo Shortcodes
GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Read File Contents

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

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