|
1 |
| -{{/* Use to include Markdown snippets. Note that the included content can have |
2 |
| -calls to shortcodes. */ -}} |
| 1 | +{{/* |
3 | 2 |
|
4 |
| -{{ $path := .Get (cond .IsNamedParams "file" 0) -}} |
5 |
| -{{ $args := .Params -}} |
6 |
| -{{ $page := partial "func/find-include.html" (dict "path" $path "page" .Page) -}} |
7 |
| -{{ with $page -}} |
8 |
| - {{ $content := .RenderShortcodes -}} |
9 |
| - {{ range $k, $v := $args -}} |
10 |
| - {{ $regex := printf "\\{\\{\\s*\\$%s\\s*\\}\\}" (string $k) -}} |
11 |
| - {{ $content = replaceRE $regex $v $content -}} |
12 |
| - {{ end -}} |
13 |
| - {{ $content -}} |
14 |
| -{{ else -}} |
15 |
| - {{ $msg := printf |
16 |
| - "Can't include '%s': file not found in page or ancestor contexts of page %s." |
17 |
| - $path .Page.Path -}} |
18 |
| - {{ warnf $msg -}} |
| 3 | +Use to include markdown snippets. Note that the included content can have calls |
| 4 | +to shortcodes. Arguments to this shortcode can be named or positional. |
| 5 | + |
| 6 | +The first argument (optionally named "file") is mandatory, it is the path to the |
| 7 | +file to include. The path is relative to the content directory. Search will be |
| 8 | +done in '_includes' folders unless the argument starts with a dot or slash. |
| 9 | + |
| 10 | +The value of other positional or named arguments will be used to replace |
| 11 | +occurrences of '{{ $key }}' in the included content, where 'key' is the name of |
| 12 | +the argument or its position in the list of positional arguments. |
19 | 13 |
|
20 |
| - <div class="alert alert-warning"> |
21 |
| - <div class="h4 alert-heading">INTERNAL SITE ERROR</div> |
22 |
| - {{ $msg }} |
23 |
| - </div> |
| 14 | +*/ -}} |
| 15 | + |
| 16 | +{{ $path := .Get (cond .IsNamedParams "file" 0) -}} |
| 17 | +{{ $args := dict "_dot" . "_path" $path -}} |
| 18 | +{{/* Add the positional and named params to our $args map. */ -}} |
| 19 | +{{ range $i, $v := .Params -}} |
| 20 | + {{ $args = merge $args (dict (string $i) $v) -}} |
24 | 21 | {{ end -}}
|
| 22 | +{{ partial "include.md" $args -}} |
0 commit comments