29 lines
696 B
Go
29 lines
696 B
Go
package layouts
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// Render renders a page. If the query paramenter "c" is set
|
|
// the component gets rendered without the layout
|
|
func Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) {
|
|
withLayout := !r.URL.Query().Has("c")
|
|
fmt.Println("layout: ", withLayout)
|
|
|
|
slog.Debug("HX-Request", "value", r.Header.Get("HX-Request"))
|
|
if r.Header.Get("HX-Request") != "true" {
|
|
ctx = templ.WithChildren(ctx, component)
|
|
component = Base("Schreifuchs")
|
|
}
|
|
|
|
if err := component.Render(ctx, w); err != nil {
|
|
slog.Error("error while rendering component", "err", err, "ctx", ctx)
|
|
}
|
|
}
|