head

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package head keeps the elements a page writes into the document's <head>, such as <link rel="canonical">, <meta name="description">, alternate and feed links and structured data, right when a partial response swaps only a part of the page.

A region in <head> cannot go out of band as other regions do: <head> holds no element that could wrap it, and its elements change in number from page to page, such as the alternate links of the languages a page is in. Region makes a partial such a region: on a full page its output sits between two empty <template> markers, and out of band it replaces whatever is between them, as a group, so elements of the page left are removed rather than kept next to the new ones:

region := head.Region(partial.NewID("head", "regions/head.gohtml"))
slots.Set(root, "head", region, slots.OOB())

With htmx (2 and 4) the group is replaced with two out-of-band swaps that need no extension: a delete of the elements between the markers and an insert before the end marker. A <title> in the region's output goes on its own, outside the markers, where htmx takes it for the document's title. Connectors whose out-of-band attribute is not hx-swap-oob, such as Unpoly's, get the region's output as it is.

A back or forward navigation that htmx restores from its history replaces the body and the title only, so the head keeps the region's elements of the page left. With htmx 2, historyCacheSize 0 and refreshOnHistoryMiss true in its configuration make such a navigation load the whole page.

Index

Constants

View Source
const (
	// StartAttr marks the empty <template> before the region's elements,
	// with the region's ID as value.
	StartAttr = "data-partial-head"
	// EndAttr marks the empty <template> after them.
	EndAttr = "data-partial-head-end"
)

Variables

This section is empty.

Functions

func Region

func Region(p *partial.Partial) *partial.Partial

Region makes p, a region of a layout placed in <head>, replace the elements it wrote before when it goes out of band, rather than being swapped by ID; see the package documentation. p's own render stages get a stage that writes the markers and the swaps; partials p renders are not affected.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL