Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions layouts/blog/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
{{ partial "taxonomy_terms_clouds.html" . }}
</aside>
<main class="col-12 col-md-9 col-xl-8 ps-md-5 pe-md-4" role="main">
{{ if .Page.Params.banner }}
{{ if .Page.Params.banner_file }}
{{ $bannerfile := printf "hooks/%s" $.Page.Params.banner_file }}
{{ partial $bannerfile . }}
{{ else }}
{{ partial "hooks/banner.html" . }}
{{ end }}
{{ end }}
{{ with .CurrentSection.OutputFormats.Get "rss" -}}
<a class="td-rss-button" title="RSS" href="{{ .RelPermalink | safeURL }}" target="_blank" rel="noopener">
<i class="fa-solid fa-rss" aria-hidden="true"></i>
Expand Down
8 changes: 8 additions & 0 deletions layouts/docs/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
</aside>
<main class="col-12 col-md-9 col-xl-8 ps-md-5" role="main">
{{ partial "version-banner.html" . }}
{{ if .Page.Params.banner }}
{{ if .Page.Params.banner_file }}
{{ $bannerfile := printf "hooks/%s" $.Page.Params.banner_file }}
{{ partial $bannerfile . }}
{{ else }}
{{ partial "hooks/banner.html" . }}
{{ end }}
{{ end }}
{{ if not .Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" . }}{{ end }}
{{ block "main" . }}{{ end }}
</main>
Expand Down
26 changes: 26 additions & 0 deletions userguide/content/en/docs/adding-content/banners.md
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally, explain explicitly that layouts/partials/hooks/banner.html can serve a banner that is defined at build time, or even an element that actually gets populated client side.

Optional because the PR already says anything's possible, just some people might not realise how broad this is.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: "Banners"
date: 2024-02-22
weight: 12
description: >
Add a banner above the page content.
---

You can add custom banners above the page content of documentation and blog pages.

To display the banner, you have to:

1. Create a file in your project called `layouts/partials/hooks/banner.html`
1. Edit the file to add the content of the banner. You can use HTML code, or anything that [Hugo partial templates](https://gohugo.io/templates/partials/) support. For example:

```html
<div class="pageinfo pageinfo-primary">
<p>This is a simple banner that appears if you set <code>banner</code> to <code>yes</code> in the front matter of the page.</p>
</div>
```

1. Set the `banner` option to `yes` in the front matter of the page you want the banner on.

To apply the banner to multiple pages, you can also [cascade](https://gohugo.io/content-management/front-matter/#cascade) the `banner` value.

If you want to use multiple different banners in your docs, you can create multiple separate banner files called `layouts/partials/hooks/<custom-banner-filename>`, and set the `banner` option to `yes`, and the `banner_file` option to `<custom-banner-filename>` in the front matter to display the specified file as banner. Note that currently only one banner can be displayed on a page: if you have both `banner` and `banner_class` set, only `banner_class` takes effect.
Loading