use themes
This commit is contained in:
35
themes/parser.go
Normal file
35
themes/parser.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package parser // Declare the package at the top
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"your_project_path/config" // Adjust import path as needed
|
||||
"your_project_path/themes" // Adjust import path as needed
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// RenderTemplate renders a template based on the current theme
|
||||
func RenderTemplate(c *gin.Context, tmpl string, data gin.H) {
|
||||
// Get the current theme
|
||||
theme := config.GetCurrentTheme()
|
||||
|
||||
// Construct the template path: "themes/default/home.html"
|
||||
tplPath := fmt.Sprintf("themes/%s/%s", theme, tmpl)
|
||||
|
||||
// Render the template using html/template
|
||||
c.HTML(http.StatusOK, tplPath, data)
|
||||
}
|
||||
|
||||
// SwitchTheme handles POST requests to switch the current theme
|
||||
func SwitchTheme(c *gin.Context) {
|
||||
newTheme := c.PostForm("theme")
|
||||
manager := themes.GetManager()
|
||||
|
||||
if err := manager.LoadTheme(newTheme); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
} else {
|
||||
config.SetCurrentTheme(newTheme) // Update the configuration
|
||||
c.JSON(http.StatusOK, gin.H{"status": "success"})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user