+13
-2
@@ -7,19 +7,30 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
type Layouts struct {
|
||||
cfg config.Cfg
|
||||
}
|
||||
|
||||
func New(cfg config.Cfg) *Layouts {
|
||||
return &Layouts{
|
||||
cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
func (l *Layouts) 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")
|
||||
component = Base(l.cfg, "Schreifuchs")
|
||||
}
|
||||
|
||||
if err := component.Render(ctx, w); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user