Documentation
¶
Overview ¶
Package banners shows editor-managed banners anywhere on the site: hero slides on the home page, a carousel, or a scheduled announcement bar at the top of every page. A banner has a title, subtitle, Markdown text, a button (label and address), an image, a tone and an optional window in which it is shown. Banners are kept in a manually ordered list and published one by one.
One site usually has several instances, one per place banners appear:
app.Use(
banners.Module("hero", "Hero"),
banners.Module("notice", "Notices"),
)
The module is not placed on a page; templates show banners with template functions:
{{range banners "hero"}}
<section class="slide">
{{with .ImageURL}}<img src="{{.}}" alt="">{{end}}
<h2>{{.Title}}</h2>
<p>{{.Subtitle}}</p>
{{.Text}}
{{if .ButtonURL}}<a href="{{.ButtonURL}}">{{.ButtonLabel}}</a>{{end}}
</section>
{{end}}
{{with banner "notice"}}
<div class="notice notice-{{.Tone}}">{{.Title}} {{.Text}}</div>
{{end}}
banners returns the active banners of an instance in their order; banner returns the first active one, or nil. A banner is active when it is published, has a title in the page's language and the current time is inside its window (from Starts, until Ends; either may be open). The fields templates can use are those of Banner.
Index ¶
Constants ¶
const ( // ToneInfo is a neutral announcement; it is the default. ToneInfo = "info" // ToneSuccess is good news. ToneSuccess = "success" // ToneWarning asks for attention, such as a closure. ToneWarning = "warning" )
Tones are the looks an editor can give a banner; templates use them as a CSS class, for example notice-warning.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Banner ¶
type Banner struct {
ID string
Title string
Subtitle string
// Text is the rendered Markdown text.
Text template.HTML
ButtonLabel string
// ButtonURL is empty when the banner has no button. It is a template.URL,
// checked when the banner was saved, so mailto: and tel: links work in
// href attributes.
ButtonURL template.URL
// ImageURL is the banner's image as pages show it, at most media.ImageWidth
// wide (see frontend.Frontend.Image); ImageSrcset lists smaller
// copies for a srcset attribute, ImageWidth and ImageHeight are the
// size of ImageURL and ImageOriginalURL is the uploaded file, for
// downloads. All are empty when the banner has no image.
ImageURL string
ImageSrcset string
ImageOriginalURL string
ImageWidth int
ImageHeight int
// Tone is ToneInfo, ToneSuccess or ToneWarning.
Tone string
// Starts and Ends are the window the banner is shown in; zero when open.
Starts time.Time
Ends time.Time
}
Banner is an active banner as templates see it.
type Fields ¶
type Fields struct {
Image string `db:"image_id,null"`
Tone string `db:"tone"`
Starts *time.Time `db:"starts_at"`
Ends *time.Time `db:"ends_at"`
}
Fields are the language-independent parts of a banner. Starts and Ends are UTC; nil means the window is open on that side.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is one Banners instance, for the website's own code.
type Text ¶
type Text struct {
Title string `db:"title"`
Subtitle string `db:"subtitle"`
Body string `db:"body"`
ButtonLabel string `db:"button_label"`
ButtonURL string `db:"button_url"`
}
Text is a banner in one language. Body is Markdown. ButtonURL is a path on the site, such as /en/contact, or a full URL.