forked from goffee/cup
100 lines
2.2 KiB
Go
100 lines
2.2 KiB
Go
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
|
|
// Use of this source code is governed by MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
|
|
"git.smarteching.com/goffee/core"
|
|
"git.smarteching.com/goffee/core/template/components"
|
|
)
|
|
|
|
// Show home page
|
|
func Themedemo(c *core.Context) *core.Response {
|
|
|
|
// check if template engine is enabled
|
|
TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE")
|
|
if TemplateEnableStr == "" {
|
|
TemplateEnableStr = "false"
|
|
}
|
|
TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr)
|
|
|
|
if TemplateEnable {
|
|
|
|
// first, include all compoments
|
|
type templateData struct {
|
|
PageCard components.PageCard
|
|
}
|
|
|
|
// now fill data of the components
|
|
tmplData := templateData{
|
|
PageCard: components.PageCard{
|
|
CardTitle: "Card title",
|
|
CardBody: "Loerm ipsum at deim",
|
|
},
|
|
}
|
|
|
|
return c.Response.Template("custom_theme_base.html", tmplData)
|
|
|
|
} else {
|
|
|
|
message := "{\"message\": \"Error, template not enabled\"}"
|
|
return c.Response.Json(message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Show form element page
|
|
func Themeform(c *core.Context) *core.Response {
|
|
|
|
// check if template engine is enabled
|
|
TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE")
|
|
if TemplateEnableStr == "" {
|
|
TemplateEnableStr = "false"
|
|
}
|
|
TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr)
|
|
|
|
if TemplateEnable {
|
|
|
|
// first, include all compoments
|
|
type templateData struct {
|
|
FormText components.FormInput
|
|
FormEmail components.FormInput
|
|
FormButton components.FormButton
|
|
}
|
|
|
|
// now fill data of the components
|
|
tmplData := templateData{
|
|
FormText: components.FormInput{
|
|
ID: "text",
|
|
Label: "Name",
|
|
Type: "text",
|
|
Hint: "This is sample hint",
|
|
Placeholder: "Enter your name",
|
|
},
|
|
FormEmail: components.FormInput{
|
|
ID: "email",
|
|
Label: "Email",
|
|
Type: "email",
|
|
Placeholder: "Enter your email address",
|
|
},
|
|
FormButton: components.FormButton{
|
|
Text: "Login",
|
|
IsSubmit: true,
|
|
IsPrimary: true,
|
|
},
|
|
}
|
|
return c.Response.Template("custom_theme_formpage.html", tmplData)
|
|
|
|
} else {
|
|
|
|
message := "{\"message\": \"Error, template not enabled\"}"
|
|
return c.Response.Json(message)
|
|
|
|
}
|
|
|
|
}
|