Debian Codegraph @

docs/content/en/_common/render-hooks/pageinner.md

raw
1 ---
2 _comment: Do not remove front matter.
3 ---
4
5 ## PageInner details
6
7 The primary use case for `PageInner` is to resolve links and [page resources](g) relative to an included `Page`. For example, create an "include" shortcode to compose a page from multiple content files, while preserving a global context for footnotes and the table of contents:
8
9 ```go-html-template {file="layouts/_shortcodes/include.html" copy=true}
10 {{ with .Get 0 }}
11 {{ with $.Page.GetPage . }}
12 {{- .RenderShortcodes }}
13 {{ else }}
14 {{ errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }}
15 {{ end }}
16 {{ else }}
17 {{ errorf "The %q shortcode requires a positional parameter indicating the logical path of the file to include. See %s" .Name .Position }}
18 {{ end }}
19 ```
20
21 Then call the shortcode in your Markdown:
22
23 ```md {file="content/posts/post-1.md"}
24 {{%/* include "/posts/post-2" */%}}
25 ```
26
27 Any render hook triggered while rendering `/posts/post-2` will get:
28
29 - `/posts/post-1` when calling `Page`
30 - `/posts/post-2` when calling `PageInner`
31
32 `PageInner` falls back to the value of `Page` if not relevant, and always returns a value.
33
34 > [!NOTE]
35 > The `PageInner` method is only relevant for shortcodes that invoke the [`RenderShortcodes`][] method, and you must call the shortcode using [Markdown notation][].
36
37 As a practical example, Hugo's embedded link and image render hooks use the `PageInner` method to resolve markdown link and image destinations. See the source code for each:
38
39 - [Embedded link render hook][]
40 - [Embedded image render hook][]
41
42 [Embedded image render hook]: <{{% eturl render-image %}}>
43 [Embedded link render hook]: <{{% eturl render-link %}}>
44 [Markdown notation]: /content-management/shortcodes/#notation
45 [`RenderShortcodes`]: /methods/page/rendershortcodes/