Skip to content

Commit

Permalink
Clarify template lookup order for shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored Aug 23, 2024
1 parent cf8dd70 commit b5505d2
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions content/en/templates/shortcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,29 @@ You can organize your shortcodes in subdirectories, e.g. in `layouts/shortcodes/

Note the forward slash.

### Shortcode template lookup order

Shortcode templates have a simple [lookup order]:

1. `/layouts/shortcodes/<SHORTCODE>.html`
2. `/themes/<THEME>/layouts/shortcodes/<SHORTCODE>.html`
### Template lookup order

Hugo selects shortcode templates based on the shortcode name, the current output format, and the current language. The examples below are sorted by specificity in descending order. The least specific path is at the bottom of the list.

Shortcode name|Output format|Language|Template path
:--|:--|:--|:--
foo|html|en|layouts/shortcodes/foo.en.html
foo|html|en|layouts/shortcodes/foo.html.html
foo|html|en|layouts/shortcodes/foo.html
foo|html|en|layouts/shortcodes/foo.html.en.html

Shortcode name|Output format|Language|Template path
:--|:--|:--|:--
foo|rss|en|layouts/shortcodes/foo.en.xml
foo|rss|en|layouts/shortcodes/foo.rss.xml
foo|rss|en|layouts/shortcodes/foo.en.html
foo|rss|en|layouts/shortcodes/foo.rss.en.xml
foo|rss|en|layouts/shortcodes/foo.xml
foo|rss|en|layouts/shortcodes/foo.html.en.html
foo|rss|en|layouts/shortcodes/foo.html.html
foo|rss|en|layouts/shortcodes/foo.html

Note that templates provided by a theme or module always take precedence.

### Positional vs. named arguments

Expand Down

0 comments on commit b5505d2

Please sign in to comment.