hugo-theme-relearn/exampleSite/content/shortcodes/attachments.en.md
2023-01-14 01:39:28 +01:00

4 KiB

+++ description = "List of files attached to a page" title = "Attachments" +++

The attachments shortcode displays a list of files attached to a page with adjustable color, title and icon.

{{% attachments sort="asc" /%}}

Usage

While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.

{{< tabs groupId="shortcode-parameter">}} {{% tab name="shortcode" %}}

{{%/* attachments sort="asc" /*/%}}

{{% /tab %}} {{% tab name="partial" %}}

{{ partial "shortcodes/attachments.html" (dict
  "context" .
  "sort" "asc"
)}}

{{% /tab %}} {{< /tabs >}}

The shortcode lists files found in a specific folder. The name of the folder depends on your page type (either branch bundle, leaf bundle or page).

  1. For simple pages, attachments 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 branch or leaf bundle, attachments must be placed in a nested _index.files or index.files folder, accordingly.

    For branch bundles:

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

    For leaf bundles:

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

Be aware that if you use a multilingual website, you will need to have as many folders as languages and the language code must be part of the folder name.

Eg. for a site in English and Piratish:

  • content
    • _index.en.md
    • _index.pir.md
    • page.en.files
      • attachment.pdf
    • page.pir.files
      • attachment.pdf
    • page.en.md
    • page.pir.md

Parameter

Name Default Notes
style transparent The color scheme used to highlight the box content.

- by severity: info, note, tip, warning
- by brand color: primary, secondary
- by color: blue, green, grey, orange, red
- by special color: default, transparent
title see notes Arbitrary text for the box title. Depending on the style there may be a default title. Any given value will overwrite the default.

- for severity styles: the matching title for the severity
- for all other colors: Attachments

If you want no title for a severity style, you have to set this parameter to " " (a non empty string filled with spaces)
icon see notes [Font Awesome icon name]({{%relref "shortcodes/icon#finding-an-icon" %}}) set to the left of the title. Depending on the style there may be a default icon. Any given value will overwrite the default.

- for severity styles: a nice matching icon for the severity
- for all other colors: paperclip

If you want no icon, you have to set this parameter to " " (a non empty d with spaces)
sort asc Sorting the output in ascending or descending order.
pattern .* A regular expressions, used to filter the attachments by file name. 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

Custom Title, List of Attachments Ending in pdf or mp4

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

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

Info Styled Box, Descending Sort Order

{{%/* attachments style="info" sort="desc" /*/%}}

{{% attachments style="info" sort="desc" /%}}

Style and Icons

For further examples for style, title and icon, see the [notice shortcode]({{% relref "shortcodes/notice" %}}) documentation. The parameter are working the same way for both shortcodes, besides having different defaults.