File Content

Shortcode to read content from page resources, site resources or project files, it's useful to reuse the content, such as the code snippets.

File Selection Order

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

Syntax

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

Parameters

name

PositionNameTypeRequiredDefaultSinceExample
#0namestring---

The filename.

Examples

Reading From Page Resources

content/docs/helpers/file-content/data/foo.txt
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="ln">1</span><span class="cl">bar

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

Reading From Site Resources

assets/data/hello.js
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-js" data-lang="js"><span class="line"><span class="ln">1</span><span class="cl"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Hello world!&#39;</span><span class="p">)</span>

Source
1{{< file-content "data/hello.js" >}}
Result

Reading From Project Files

static/ads.txt
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="ln">1</span><span class="cl">google.com, pub-7827859788508375, DIRECT, f08c47fec0942fa0

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

Reading From Nonexistent File

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

Combine With Other Shortcodes

Take Bootstrap config toggle as an example.

content/docs/helpers/file-content/data/hugo.yaml
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="ln">1</span><span class="cl"><span class="nt">title</span><span class="p">:</span><span class="w"> </span><span class="l">Site Title</span><span class="w">

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

hugo.yaml

1title: Site Title

hugo.toml

1title = 'Site Title'

hugo.json

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