From 57df54999e778887e66775481dab46191b46d0b6 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 7 Mar 2026 17:15:38 +0530 Subject: Refactor dashboard templates and enhance URL handling - Added `variableName` to `urlNode` struct for improved variable handling in URL tags. - Updated `url` function to support variable assignment using the `as` keyword. - Removed deprecated `dashboard.django` template and replaced it with a new layout structure. - Introduced partial templates for header and sidebar to streamline dashboard layout. - Created new HTMX templates for mailboxes, mailbox, overview, and users to enhance dynamic content loading. - Implemented navigation JavaScript to manage active link states in the sidebar. - Refactored render functions to resolve template paths based on HTMX requests. - Updated constants for request key naming consistency. --- utils/meta/constants.go | 2 +- utils/shortcuts/functions.go | 13 +++++++++++++ utils/shortcuts/render.go | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/meta/constants.go b/utils/meta/constants.go index 3f2ce68..0138884 100644 --- a/utils/meta/constants.go +++ b/utils/meta/constants.go @@ -2,5 +2,5 @@ package meta const ( LOG_PREFIX = "Meta" - REQUEST_KEY = "__request" + REQUEST_KEY = "Request" ) diff --git a/utils/shortcuts/functions.go b/utils/shortcuts/functions.go index df00dcf..3e76a9a 100644 --- a/utils/shortcuts/functions.go +++ b/utils/shortcuts/functions.go @@ -1,7 +1,9 @@ package shortcuts import ( + "fmt" "maps" + "path" "reflect" "strings" @@ -11,6 +13,17 @@ import ( "github.com/gofiber/fiber/v2" ) +func resolveTemplate(context *fiber.Ctx, templateName string) string { + switch { + case context.Get("HX-Request") == "true" && context.Get("HX-Boosted") != "true": + directory := path.Dir(templateName) + filename := path.Base(templateName) + return fmt.Sprintf("%s/htmx/%s.htmx", directory, filename) + default: + return templateName + } +} + func mergeContextValues(context *fiber.Ctx, targetMap fiber.Map) { context.Context().VisitUserValues(func(key []byte, value any) { targetMap[string(key)] = value diff --git a/utils/shortcuts/render.go b/utils/shortcuts/render.go index 29c7a8f..e91ccfa 100644 --- a/utils/shortcuts/render.go +++ b/utils/shortcuts/render.go @@ -13,7 +13,7 @@ func Render(context *fiber.Ctx, templateName string, data any) error { } } - return context.Render(templateName, templateData) + return context.Render(resolveTemplate(context, templateName), templateData) } func RenderWithStatus(context *fiber.Ctx, templateName string, data any, statusCode int) error { -- cgit v1.2.3