go-html/cmd/wasm/render_layout.go
Snider a02843a5ad
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
fix(wasm): render empty slot content
Preserve empty string slot values in renderToString so explicit empty slots still render as empty containers.\n\nCo-Authored-By: Virgil <virgil@lethean.io>
2026-04-15 02:42:50 +01:00

44 lines
884 B
Go

// SPDX-Licence-Identifier: EUPL-1.2
package main
import html "dappco.re/go/core/html"
// renderLayout renders an HLCRF layout from a slot map.
//
// Empty string values are meaningful: they create an explicit empty slot
// container rather than being treated as absent input.
func renderLayout(variant, locale string, slots map[string]string) string {
if variant == "" {
return ""
}
ctx := html.NewContext()
if locale != "" {
ctx.SetLocale(locale)
}
layout := html.NewLayout(variant)
for _, slot := range []string{"H", "L", "C", "R", "F"} {
content, ok := slots[slot]
if !ok {
continue
}
switch slot {
case "H":
layout.H(html.Raw(content))
case "L":
layout.L(html.Raw(content))
case "C":
layout.C(html.Raw(content))
case "R":
layout.R(html.Raw(content))
case "F":
layout.F(html.Raw(content))
}
}
return layout.Render(ctx)
}