Skip to content

Commit

Permalink
🎨 Add template type column to Attribute View siyuan-note#8766
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 1, 2023
1 parent 0aa61fe commit bfd27a6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions kernel/model/attribute_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,22 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
render := func(blockID string) string {
funcMap := sprig.TxtFuncMap()
goTpl := template.New("").Delims(".action{", "}")
tpl, tplErr := goTpl.Funcs(funcMap).Parse(col.Template)
tplContent := col.Template
tplContent = strings.ReplaceAll(tplContent, ".custom-", ".custom_")
tpl, tplErr := goTpl.Funcs(funcMap).Parse(tplContent)
if nil != tplErr {
logging.LogWarnf("parse template [%s] failed: %s", col.Template, tplErr)
logging.LogWarnf("parse template [%s] failed: %s", tplContent, tplErr)
return ""
}

buf := &bytes.Buffer{}
ial := GetBlockAttrs(blockID)
if err = tpl.Execute(buf, ial); nil != err {
logging.LogWarnf("execute template [%s] failed: %s", col.Template, err)
dataModel := map[string]string{}
for k, v := range ial {
dataModel[strings.ReplaceAll(k, "custom-", "custom_")] = v
}
if err = tpl.Execute(buf, dataModel); nil != err {
logging.LogWarnf("execute template [%s] failed: %s", tplContent, err)
}
return buf.String()
}
Expand Down

0 comments on commit bfd27a6

Please sign in to comment.