fix render public root bug

This commit is contained in:
Max 2024-08-10 17:18:35 +08:00
parent 80779bb0fc
commit 0f6bc06172
3 changed files with 12 additions and 2 deletions

View file

@ -126,7 +126,13 @@ func TemplateRender(process *process.Process) interface{} {
exception.New(err.Error(), 500).Throw() exception.New(err.Error(), 500).Throw()
} }
root, err := sui.PublicRootWithSid(process.Sid) opt := process.ArgsMap(4, map[string]interface{}{})
params, ok := opt["params"].(map[string]interface{})
if !ok {
params = map[string]interface{}{}
}
root, err := sui.PublicRoot(params)
if err != nil { if err != nil {
exception.New(err.Error(), 500).Throw() exception.New(err.Error(), 500).Throw()
} }
@ -145,7 +151,6 @@ func TemplateRender(process *process.Process) interface{} {
} }
data := process.ArgsMap(3) data := process.ArgsMap(3)
opt := process.ArgsMap(4, map[string]interface{}{})
option := core.ParserOption{ option := core.ParserOption{
Theme: opt["theme"], Theme: opt["theme"],
Locale: opt["locale"], Locale: opt["locale"],

View file

@ -29,6 +29,7 @@ type SUI interface {
PublicRootMatcher() *Matcher PublicRootMatcher() *Matcher
GetPublic() *Public GetPublic() *Public
PublicRootWithSid(sid string) (string, error) PublicRootWithSid(sid string) (string, error)
PublicRoot(data map[string]any) (string, error)
} }
// ITemplate is the interface for the ITemplate // ITemplate is the interface for the ITemplate

View file

@ -98,6 +98,8 @@ func (script *Script) Call(r *Request, method string, args ...any) (interface{},
} }
defer ctx.Close() defer ctx.Close()
// Set the sid
ctx.Sid = r.Sid
res, err := ctx.Call(method, args...) res, err := ctx.Call(method, args...)
if err != nil { if err != nil {
return nil, err return nil, err
@ -118,6 +120,8 @@ func (script *Script) BeforeRender(r *Request, props map[string]interface{}) (Da
return nil, nil return nil, nil
} }
// Set the sid
ctx.Sid = r.Sid
res, err := ctx.Call("BeforeRender", r, props) res, err := ctx.Call("BeforeRender", r, props)
if err != nil { if err != nil {
return nil, err return nil, err