File Content Shortcode

Reading content from page resources, site resources or static files, it's useful to reuse the content, such as the code snippets, notes and so on.

File Selection Order§

  1. Page resource.
  2. Site resource.
  3. Project files.

Syntax§

1{{< file-content "/path/to/file" >}}
markdown

Parameters§

name§

PositionNameTypeDefaultRequired
#0namestring-Y

The filename.

Examples§

Reading From Page Resource§

1{{< file-content "data/foo.txt" >}}
markdown
bar

Reading From Site Resource§

1console.log('Hello world!')
js
1```js
2{{< file-content "data/hello.js" >}}
3```
markdown
1console.log('Hello world!')
js

Reading From Projects File§

1google.com, pub-7827859788508375, DIRECT, f08c47fec0942fa0
text
1{{< file-content "static/ads.txt" >}}
markdown
google.com, pub-7827859788508375, DIRECT, f08c47fec0942fa0

Reading From Nonexistent File§

1{{< file-content "static/invalid.txt" >}}
markdown

Combine With Other Shortcodes§

Take Bootstrap config toggle as an example.

1{{< bs/config-toggle hugo >}}
2{{< file-content "data/hugo.yaml" >}}
3{{< /bs/config-toggle >}}
markdown

hugo.yaml

1title: Site Title
yaml

hugo.toml

1title = 'Site Title'
toml

hugo.json

1{
2   "title": "Site Title"
3}
json