fix(templates): 增强模板加载和执行的错误处理- 在 layout_executor.go 中添加了对 getTemplates 返回值的空指针检查
- 当 getTemplates未定义或返回 nil 时,打印错误信息并提前返回 - 在 template_loader.go 中引入 fmt 包用于调试日志输出 - 在模板加载逻辑中增加调试信息打印,便于追踪 getTemplates 函数执行状态 - 添加了 doLoad 函数执行的调试日志,帮助定位模板加载问题
This commit is contained in:
@@ -27,6 +27,10 @@ func (proc *LayoutTemplateProcessor) ExecTemplateWithFunc(writer io.Writer, name
|
||||
layoutName := ""
|
||||
// 获取模板列表
|
||||
localTemplates := getTemplates()
|
||||
if localTemplates == nil {
|
||||
fmt.Printf("获取模板失败, getTemplates 没有定义 : %v 模板参数: %v \n", name, data)
|
||||
return
|
||||
}
|
||||
// 执行函数
|
||||
localTemplates.Funcs(map[string]interface{}{
|
||||
// 替换body内容
|
||||
|
||||
@@ -2,6 +2,7 @@ package templates
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"platform/config"
|
||||
"sync"
|
||||
@@ -17,7 +18,13 @@ func LoadTemplates(c config.Configuration) (err error) {
|
||||
}
|
||||
reload := c.GetBoolDefault("templates:reload", false)
|
||||
once.Do(func() {
|
||||
|
||||
fmt.Printf("设置模板 getTemplates 函数开始\n")
|
||||
|
||||
doLoad := func() (t *template.Template) {
|
||||
|
||||
fmt.Printf("设置模板 getTemplates doLoad 函数已执行\n")
|
||||
|
||||
t = template.New("htmlTemplates")
|
||||
t.Funcs(map[string]interface{}{
|
||||
"body": func() string { return "" },
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user