Skip to main content
  1. Snippits & Exemplars/
  2. WolfspyreLabs Exemplars/
  3. WolfspyreLabs Shortcodes/

Attachments

The Attachments shortcode displays a list of files attached to a page.

Near as I can tell, This shortcode was originally developed by Nelis Oostens1.

It was subsequently added to the hugo-learn theme2, and expanded a bit 3.

Usage #

The shortcurt lists files found in a specific folder. Currently, it support two implementations for pages

  1. If your page is a markdown file, attachements must be placed in a folder named like your page and ending with .files.

    • content
      • _index.md
      • page.files
        • attachment.pdf
      • page.md
  2. If your page is a folder, attachements must be placed in a nested ‘files’ folder.

    • content
      • _index.md
      • page
        • index.md
        • files
          • attachment.pdf

Be aware that if you use a multilingual website, you will need to have as many folders as languages.

That’s all!

Logs #

Now that hugo has introduced the warnidf4 feature I’ve added knobs to disable each of the following log emission methods

  • attachments-01 : emits a log message when looking for the attachments directory.
  • attachments-02 : emitted when the attachments directory isn’t locatable. likely a legitimate thing to know about
  • attachments-03 : emitted when it cannot locate the target icon.

Parameters #

Parameter Default Description
title “Attachments” List’s title
style "" Choose between “orange”, “grey”, “blue” and “green” for nice style
pattern “.*” A regular expression, used to filter the attachments by file name. The pattern parameter value must be a regular expression.

For example:

  • To match a file suffix of ‘.jpg’, use .*\.jpg$ (not *.jpg).
  • To match file names ending in ‘.jpg’ or ‘.png’, use .*\.(jpg|png)$.

Examples #

List of attachments ending in pdf or mp4 #

{{% attachments title=“Related files” pattern=".*.(pdf|mp4)$" / /%}}

renders as

  • IMG_0409.mp4 (4 MB)
  • Colored styled box #

    {{% attachments style=“orange” / %}}

    renders as

  • IMG_0409.mp4 (4 MB)
  • RCADog.webp (2 MB)
  • Tuesdays.gif (990 KB)
  • index.md (22 B)
  • ohDear.webp (74 KB)
  • wolf.png (28 KB)
  • {{% attachments style=“grey” / %}}

    renders as

  • IMG_0409.mp4 (4 MB)
  • RCADog.webp (2 MB)
  • Tuesdays.gif (990 KB)
  • index.md (22 B)
  • ohDear.webp (74 KB)
  • wolf.png (28 KB)
  • {{% attachments style=“blue” / %}}

    renders as

  • IMG_0409.mp4 (4 MB)
  • RCADog.webp (2 MB)
  • Tuesdays.gif (990 KB)
  • index.md (22 B)
  • ohDear.webp (74 KB)
  • wolf.png (28 KB)
  • {{% attachments style=“green” / %}}

    renders as

  • IMG_0409.mp4 (4 MB)
  • RCADog.webp (2 MB)
  • Tuesdays.gif (990 KB)
  • index.md (22 B)
  • ohDear.webp (74 KB)
  • wolf.png (28 KB)