File

Share via

The file shortcode prints the full content of any given file with syntax highlighting.

Overview

The file shortcode prints and highlights the full content of a given input file. It recognizes the languages supported by Hugo’s highlight function  .

[en]
    languageName = "English"
    contentDir = "content/en"
    weight = 1
    [en.params.head]
        tagline = "A Hugo Theme"
    [en.params.footer]
        license = "Code licensed <a href='https://github.com/gethinode/hinode/blob/main/LICENSE' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>MIT</a>, docs <a href='https://creativecommons.org/licenses/by-nc/4.0/' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>CC BY-NC 4.0</a>"

[[en.params.featured.actions]]
    url = "docs/getting-started/introduction/"
    title = "Get Started"
    icon = "fas book-open"

[[en.params.featured.actions]]
    url = "https://demo.gethinode.com"
    title = "Live Demo"
    icon = "fas display"
    outline = true
markdown
{{< file path="./config/_default/languages.toml" id="file-collapse-1" >}}

Arguments

The shortcode supports the following arguments:

ArgumentRequiredDescription
pathYesPath of the input file. The path is relative to the basePath defined in the docs section of the site’s parameters (see page layout). If the file starts with ./, the path of the repository is used as base path instead.
langNoLanguage to be used by the syntax highlighter. When no language is specified, the shortcode derives the language from the input file’s extension.
showNoIf unset, shows the panel with the code snippet in collapsed state. By default, the panel is expanded.
fullNoIf unset, shows the filename only. By default, the full relative path is shown.
idNoOptional id of the collapse panel, defaults to “file-collapse-n” with a sequential number n starting at 1.
classNoOptional class argument of the tab control.

Examples

Change the style and language of your file preview with shortcode arguments.

Default file preview

Use the path argument to print the content of a specific file. By default, the shortcode uses the site’s basePath (see page layout for more information).

# toml-docs-start lang-main
[en]
    languageName = "English"
    contentDir = "content/en"
    weight = 1
# toml-docs-end lang-main
# toml-docs-start lang-param
    [en.params.head]
        tagline = "A Hugo Theme"
    [en.params.feature]
        link = "about"
        caption = "About"
    [en.params.footer]
        license = "Licensed under Creative Commons (<a href='https://creativecommons.org/licenses/by-nc-sa/4.0/' class='link-secondary' target='_blank' rel='noopener noreferrer'>CC BY-NC-SA 4.0</a>)."
        socialTitle = "Follow me"
        socialCaption = "I work on everything coding and tweet developer memes"
# toml-docs-end lang-param

[nl]
    languageName = "Nederlands"
    contentDir = "content/nl"
    weight = 2
    [nl.params.head]
        tagline = "Een Hugo Thema"
    [nl.params.feature]
        link = "over-mij"
        caption = "Over mij"
    [nl.params.footer]
        license = "Gelicenseerd onder Creative Commons (<a href='https://creativecommons.org/licenses/by-nc-sa/4.0/' class='link-secondary' target='_blank' rel='noopener noreferrer'>CC BY-NC-SA 4.0</a>)."
        socialTitle = "Volg mij"
        socialCaption = "Ik doe aan programmeren en tweet memes"
markdown
{{< file path="config/_default/languages.toml" id="file-collapse-2" >}}

Provide a path that starts with ./ to use the path of the repository as base path instead.

[en]
    languageName = "English"
    contentDir = "content/en"
    weight = 1
    [en.params.head]
        tagline = "A Hugo Theme"
    [en.params.footer]
        license = "Code licensed <a href='https://github.com/gethinode/hinode/blob/main/LICENSE' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>MIT</a>, docs <a href='https://creativecommons.org/licenses/by-nc/4.0/' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>CC BY-NC 4.0</a>"

[[en.params.featured.actions]]
    url = "docs/getting-started/introduction/"
    title = "Get Started"
    icon = "fas book-open"

[[en.params.featured.actions]]
    url = "https://demo.gethinode.com"
    title = "Live Demo"
    icon = "fas display"
    outline = true
markdown
{{< file path="./config/_default/languages.toml" id="file-collapse-3" >}}

Collapsed file preview

Set show to false to hide the file content on page load. The content is reveiled when clicking the tab control.

[en]
    languageName = "English"
    contentDir = "content/en"
    weight = 1
    [en.params.head]
        tagline = "A Hugo Theme"
    [en.params.footer]
        license = "Code licensed <a href='https://github.com/gethinode/hinode/blob/main/LICENSE' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>MIT</a>, docs <a href='https://creativecommons.org/licenses/by-nc/4.0/' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>CC BY-NC 4.0</a>"

[[en.params.featured.actions]]
    url = "docs/getting-started/introduction/"
    title = "Get Started"
    icon = "fas book-open"

[[en.params.featured.actions]]
    url = "https://demo.gethinode.com"
    title = "Live Demo"
    icon = "fas display"
    outline = true
markdown
{{< file show="false"  path="./config/_default/languages.toml" id="file-collapse-4" >}}

File preview with filename only

Set full to false to show the filename only.

[en]
    languageName = "English"
    contentDir = "content/en"
    weight = 1
    [en.params.head]
        tagline = "A Hugo Theme"
    [en.params.footer]
        license = "Code licensed <a href='https://github.com/gethinode/hinode/blob/main/LICENSE' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>MIT</a>, docs <a href='https://creativecommons.org/licenses/by-nc/4.0/' class='link-bg-footer fw-medium' target='_blank' rel='noopener noreferrer'>CC BY-NC 4.0</a>"

[[en.params.featured.actions]]
    url = "docs/getting-started/introduction/"
    title = "Get Started"
    icon = "fas book-open"

[[en.params.featured.actions]]
    url = "https://demo.gethinode.com"
    title = "Live Demo"
    icon = "fas display"
    outline = true
markdown
{{< file full="false" path="./config/_default/languages.toml" id="file-collapse-5" >}}
Last updated: August 5, 2023 • Add file shortcode (52482a2)