diff --git a/layout.go b/layout.go
index d9f60c8..4b11aab 100644
--- a/layout.go
+++ b/layout.go
@@ -43,6 +43,7 @@ type NavItem struct {
type PageHeader struct {
Title string
Name string // lowercase product name, e.g. "yasta"; used in
and the footer
+ Lang string // ; "" defaults to "en"
Brand string // navbar brand text, e.g. "YASTA"
BrandInitial string // single-letter favicon glyph, e.g. "y"
Subtitle string
@@ -63,9 +64,11 @@ type PageHeader struct {
// and the sidebar's tag -- an escape hatch for a
// consuming project's own client-side framework state (e.g. yakwui's
// Alpine.js collapsible sidebar), which the shared markup has no
- // generic opinion about.
- BodyAttrs template.HTML
- SidebarAttrs template.HTML
+ // generic opinion about. template.HTMLAttr, not template.HTML --
+ // html/template's contextual autoescaper requires the attribute-list
+ // sentinel type in this position or it silently drops the value.
+ BodyAttrs template.HTMLAttr
+ SidebarAttrs template.HTMLAttr
}
// Renderer holds one independently parsed *template.Template per page:
diff --git a/layout_test.go b/layout_test.go
index 3e837f5..02ba8de 100644
--- a/layout_test.go
+++ b/layout_test.go
@@ -47,6 +47,37 @@ func TestNewRendererAndPage(t *testing.T) {
`class="nav-link active"`,
"test-build",
"Dashboard ยท example",
+ ``,
+ "",
+ } {
+ if !strings.Contains(out, want) {
+ t.Errorf("rendered output missing %q\n---\n%s", want, out)
+ }
+ }
+}
+
+func TestPageHeaderOverrides(t *testing.T) {
+ r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
+ if err != nil {
+ t.Fatalf("NewRenderer: %v", err)
+ }
+
+ var buf bytes.Buffer
+ data := PageHeader{
+ Title: "Dashboard",
+ Lang: "de",
+ BodyAttrs: template.HTMLAttr(` x-data="{ open: true }"`),
+ SidebarAttrs: template.HTMLAttr(` :class="{ hidden: !open }"`),
+ }
+ if err := r.Page(&buf, "dashboard", data); err != nil {
+ t.Fatalf("Page: %v", err)
+ }
+ out := buf.String()
+
+ for _, want := range []string{
+ ``,
+ ``,
+ `sidebar d-md-block" :class="{ hidden: !open }">`,
} {
if !strings.Contains(out, want) {
t.Errorf("rendered output missing %q\n---\n%s", want, out)
diff --git a/templates/layout/base.html.tmpl b/templates/layout/base.html.tmpl
index 0587ec1..35fedfd 100644
--- a/templates/layout/base.html.tmpl
+++ b/templates/layout/base.html.tmpl
@@ -1,5 +1,5 @@
{{define "base"}}
-
+