Become a backer or sponsor to support our work.
You may want to include custom HTML markup to extend functionalities, that’s quit easy to do that with HugoPress built-in hooks and HB custom hooks.
Let’s get started with a simple example, which displays a greeting message on the top of page.
In this example, the body-begin
hook is the hook we’re looking for.
And then configure the hook.
params.toml
1[hugopress]
2 [hugopress.modules]
3 [hugopress.modules.hb-custom]
4 [hugopress.modules.hb-custom.hooks]
5 [hugopress.modules.hb-custom.hooks.body-begin]
6 cacheable = true
params.yaml
1hugopress:
2 modules:
3 hb-custom:
4 hooks:
5 body-begin:
6 cacheable: true
params.json
1{
2 "hugopress": {
3 "modules": {
4 "hb-custom": {
5 "hooks": {
6 "body-begin": {
7 "cacheable": true
8 }
9 }
10 }
11 }
12 }
13}
If everything is OK, Hugo’ll complaint about partial not found.
It’s recommended to use hb-custom
as the HugoPress module name, to avoid conflicting with other HugoPress modules.
cacheable
to improve build performance.It’s time to create the partial for including custom HTML. The partial name is related to the module and hook name.
1<p class="text-center bg-danger text-white mb-0">
2 Greeting from the body-begin hook.
3</p>
You’re able to access Page variables via .Page
, please don’t forgot disabling the cacheable
for dynamic data.
See also Hooks Context.
That’s it, now the greeting message will appear at the top of page.