From bfd27a62d1ec270cd52594a55f766862e9961c05 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 1 Oct 2023 18:22:39 +0800 Subject: [PATCH] :art: Add template type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8766 --- kernel/model/attribute_view.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index c68d1d552..3846ebe8d 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -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() }