Attachments
Projects:
Tags:
5 minute read
Shortcode to show a list of downloadable page resources resp. files in a folder.
| Parameter | Default | Description |
|---|---|---|
| title | Attachments | The title of the box with the attachments. (The default value is the language specific variable sc_attachments.) |
| icon | fas fa-paperclip | Code for FontAwesome icon left from the title. |
| folder | If empty the page resources are used for the file list. If set a specific folder relativ to the current page can be used for generating a file list. | |
| recursive | true | If true als files in subfolders will be found (only if the parameter folder is used). |
| exclude | .md,.markdown | Exclude Files with specific extenstion. By default markdown files are excluded, because they get renderd to an html file. |
| filter | . | RegEx filter on the filename relativ to the current page. |
| match | ** | Glob pattern for filtering page resources. |
| class | td-max-width-on-larger-screens | Additional HTML class for the <div> containing the box with the attachments. The default value ensures that the box is the same width as other typical content. |
| num_prec | 1 | Parameter for formating file size: Number of decimal places |
| num_fmt | - , . | Parameter for formating file size (see Hugo docs). |
| num_fmt_del | " " (=blank) | Corresponding delimiter for parameter for formating file size (see Hugo docs). |
| empty_list | No attachments found. | Shown message if file list is empty. |
| show_folder | false | Option to show also the relative file path, when paramter folder is used. |
Pure version without any parameter
The pure shortcode {{< attachments />}} displays all page resources of a page bundle. As visible Text for the links the resource parameter title is used. Default title value is the filename (relative to the owning page). Can be set in front matter.
If set, also the resource parameter params.description get displayed under the link. All the resource parameter can be set by corresponding page’s front matter.
This is the front matter of the current page:
title: "Attachments"
linkTitle: "Testing Shortcode Attachments"
weight: 1
icon: fas fa-paperclip
tags: ["Shortcode", "Attachments"]
projects: ["Docsy"]
description: >
Testing Shortcode Attachments
resources:
- src: '**.pdf'
name: pdf-file-name-:counter
title: pdf-file-title-:counter
params:
description: "This ist the description of all PDF files."
- attachments/crow.jpeg (16.6 kB)
- attachments/data.csv (0.0 Byte)
- attachments/document.doc (0.0 Byte)
- attachments/open-office.odt (0.0 Byte)
- attachments/song.mp3 (0.0 Byte)
- attachments/video.mp4 (0.0 Byte)
- crow.jpg (16.6 kB)
- files/crow.JPG (16.6 kB)
- files/data.json (0.0 Byte)
- files/document.doc (0.0 Byte)
- files/excel.xlsx (0.0 Byte)
- files/file-1.txt (0.0 Byte)
- files/goldmark-file.goldmark (0.0 Byte)
- files/htm-file.htm (0.0 Byte)
- files/html-file.html (0.0 Byte)
- files/music.mp3 (0.0 Byte)
- files/subfolder/audio.wav (0.0 Byte)
- files/TestFile.JPG (16.6 kB)
- pdf-file-title-1 (255.3 kB)
- pdf-file-title-2 (0.0 Byte)
- pdf-file-title-3 (0.0 Byte)
- pdf-file-title-4 (8.3 kB)
- pdf-file-title-5 (488.9 kB)
- screenshot.png (1.1 MB)
Pure version with inner content
Also a inner content will be shown within the attachments box:
{{< attachments >}}
#### An inner Headline
Some inner text.
{{< /attachments >}}
- attachments/crow.jpeg (16.6 kB)
- attachments/data.csv (0.0 Byte)
- attachments/document.doc (0.0 Byte)
- attachments/open-office.odt (0.0 Byte)
- attachments/song.mp3 (0.0 Byte)
- attachments/video.mp4 (0.0 Byte)
- crow.jpg (16.6 kB)
- files/crow.JPG (16.6 kB)
- files/data.json (0.0 Byte)
- files/document.doc (0.0 Byte)
- files/excel.xlsx (0.0 Byte)
- files/file-1.txt (0.0 Byte)
- files/goldmark-file.goldmark (0.0 Byte)
- files/htm-file.htm (0.0 Byte)
- files/html-file.html (0.0 Byte)
- files/music.mp3 (0.0 Byte)
- files/subfolder/audio.wav (0.0 Byte)
- files/TestFile.JPG (16.6 kB)
- pdf-file-title-1 (255.3 kB)
- pdf-file-title-2 (0.0 Byte)
- pdf-file-title-3 (0.0 Byte)
- pdf-file-title-4 (8.3 kB)
- pdf-file-title-5 (488.9 kB)
- screenshot.png (1.1 MB)
An inner Headline
Some inner text.
Using spezific Folder
Especially for none page bundles (not index.md or _index.md) it is also possible to set a specific subfolder for attachments::
{{< attachments folder="files" title="Files in folder" />}}
Using filter options
The resulting file list can be filtered by the options filter (by using RegEx on the filename relative to the current page).
{{< attachments title="Filtered page resources for jpg files" filter=".+\.(?i)(jpg|jpeg)$" />}}
{{< attachments folder="./" title="Filtered all files in base folder for 'doc'" filter="doc" >}}
Also the file `document.pdf` get listed, because it begins with "doc".
{{< /attachments >}}
document.pdf get listed, because it begins with “doc”.If displaying page resources alternatively the parameter match can get used as file list filter. But Glob pattern has to be used and the name of the page resource instead of the file name get filtered!
{{< attachments title="Filtered page resources for 'files/*'" match="files/*" />}}
All files in this test content
{{< attachments folder="./" title="All files" exclude="." show_folder=true />}}
- attachments/crow.jpeg (16.6 kB)
- attachments/data.csv (0.0 Byte)
- attachments/document.doc (0.0 Byte)
- attachments/document.pdf (0.0 Byte)
- attachments/open-office.odt (0.0 Byte)
- attachments/song.mp3 (0.0 Byte)
- attachments/video.mp4 (0.0 Byte)
- crow.jpg (16.6 kB)
- files/crow.JPG (16.6 kB)
- files/data.json (0.0 Byte)
- files/document.doc (0.0 Byte)
- files/excel.xlsx (0.0 Byte)
- files/file-1.txt (0.0 Byte)
- files/goldmark-file.goldmark (0.0 Byte)
- files/htm-file.htm (0.0 Byte)
- files/html-file.html (0.0 Byte)
- files/markdown-file.md (0.0 Byte)
- files/markdown-long.markdown (0.0 Byte)
- files/music.mp3 (0.0 Byte)
- files/subfolder/audio.wav (0.0 Byte)
- files/subfolder/printout.pdf (0.0 Byte)
- files/TestFile.JPG (16.6 kB)
- index.md (5.1 kB)
- leeres_notenpapier.pdf (8.3 kB)
- SC_paper_info.pdf (255.3 kB)
- screenshot.png (1.1 MB)
- testseite_farbdrucker.pdf (488.9 kB)
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.