[思源笔记使用心得] 分享一个渲染当前文章标题 / 命名 / 别名 / 备注等属性的模板片段

注: 找到了一个可以增删改查文档属性的挂件, 感谢开发者 leolee9086

leolee9086/cc-doctype-form


当我引用一个文档块时, 发现鼠标悬停在该引用上方弹出的预览面板中只能看到文档内容而无法看到文章的相关属性, 例如

而我习惯将这些属性设置为如下内容

但是显然悬浮预览面板无法查看这些内容, 因此我使用如下模板将这些内容以表格的形式插入

.action{$blocks := (queryBlocks "SELECT * FROM blocks WHERE type='d' AND id ='?'" .id)}
.action{$name := ""}
.action{$memo := ""}
.action{$hpath := ""}
.action{$created := ""}
.action{$updated := ""}
.action{range $i, $v := $blocks}
    .action{$name = $v.Name}
    .action{$memo = $v.Memo}
    .action{$hpath = $v.HPath}
    .action{$created = $v.Created}
    .action{$updated = $v.Updated}
.action{end}

.action{$Title := ((((((((((((((((((((((((((((((((.title | replace "\\" "\\\\" ) | replace "`" "\\`" ) | replace "-" "\\-" ) | replace "=" "\\=" ) | replace "[" "\\[" ) | replace "]" "\\]" ) | replace ";" "\\;" ) | replace "'" "\\'" ) | replace "," "\\," ) | replace "." "\\." ) | replace "/" "\\/" ) | replace "~" "\\~" ) | replace "!" "\\!" ) | replace "@" "\\@" ) | replace "#" "\\#" ) | replace "$" "\\$" ) | replace "%" "\\%" ) | replace "^" "\\^" ) | replace "&" "\\&" ) | replace "*" "\\*" ) | replace "(" "\\(" ) | replace ")" "\\)" ) | replace "_" "\\_" ) | replace "+" "\\+" ) | replace "{" "\\{" ) | replace "}" "\\}" ) | replace "|" "\\|" ) | replace ":" "\\:" ) | replace "\"" "\\\"" ) | replace "<" "\\<" ) | replace ">" "\\>" ) | replace "?" "\\?" ) }
.action{$Name := (((((((((((((((((((((((((((((((($name | replace "\\" "\\\\" ) | replace "`" "\\`" ) | replace "-" "\\-" ) | replace "=" "\\=" ) | replace "[" "\\[" ) | replace "]" "\\]" ) | replace ";" "\\;" ) | replace "'" "\\'" ) | replace "," "\\," ) | replace "." "\\." ) | replace "/" "\\/" ) | replace "~" "\\~" ) | replace "!" "\\!" ) | replace "@" "\\@" ) | replace "#" "\\#" ) | replace "$" "\\$" ) | replace "%" "\\%" ) | replace "^" "\\^" ) | replace "&" "\\&" ) | replace "*" "\\*" ) | replace "(" "\\(" ) | replace ")" "\\)" ) | replace "_" "\\_" ) | replace "+" "\\+" ) | replace "{" "\\{" ) | replace "}" "\\}" ) | replace "|" "\\|" ) | replace ":" "\\:" ) | replace "\"" "\\\"" ) | replace "<" "\\<" ) | replace ">" "\\>" ) | replace "?" "\\?" ) }
.action{$Alias := (((((((((((((((((((((((((((((((((.alias | replace "\\" "\\\\" ) | replace "`" "\\`" ) | replace "-" "\\-" ) | replace "=" "\\=" ) | replace "[" "\\[" ) | replace "]" "\\]" ) | replace ";" "\\;" ) | replace "'" "\\'" ) | replace "," "\\," ) | replace "." "\\." ) | replace "/" "\\/" ) | replace "~" "\\~" ) | replace "!" "\\!" ) | replace "@" "\\@" ) | replace "#" "\\#" ) | replace "$" "\\$" ) | replace "%" "\\%" ) | replace "^" "\\^" ) | replace "&" "\\&" ) | replace "*" "\\*" ) | replace "(" "\\(" ) | replace ")" "\\)" ) | replace "_" "\\_" ) | replace "+" "\\+" ) | replace "{" "\\{" ) | replace "}" "\\}" ) | replace "|" "\\|" ) | replace ":" "\\:" ) | replace "\"" "\\\"" ) | replace "<" "\\<" ) | replace ">" "\\>" ) | replace "?" "\\?" ) | replace "," "<br />")}
.action{$Memo := ((((((((((((((((((((((((((((((((($memo | replace "\\" "\\\\" ) | replace "`" "\\`" ) | replace "-" "\\-" ) | replace "=" "\\=" ) | replace "[" "\\[" ) | replace "]" "\\]" ) | replace ";" "\\;" ) | replace "'" "\\'" ) | replace "," "\\," ) | replace "." "\\." ) | replace "/" "\\/" ) | replace "~" "\\~" ) | replace "!" "\\!" ) | replace "@" "\\@" ) | replace "#" "\\#" ) | replace "$" "\\$" ) | replace "%" "\\%" ) | replace "^" "\\^" ) | replace "&" "\\&" ) | replace "*" "\\*" ) | replace "(" "\\(" ) | replace ")" "\\)" ) | replace "_" "\\_" ) | replace "+" "\\+" ) | replace "{" "\\{" ) | replace "}" "\\}" ) | replace "|" "\\|" ) | replace ":" "\\:" ) | replace "\"" "\\\"" ) | replace "<" "\\<" ) | replace ">" "\\>" ) | replace "?" "\\?" ) | replace "\n" "<br />")}

.action{$Hpath := (((((((((((((((((((((((((((((((($hpath | replace "\\" "\\\\" ) | replace "`" "\\`" ) | replace "-" "\\-" ) | replace "=" "\\=" ) | replace "[" "\\[" ) | replace "]" "\\]" ) | replace ";" "\\;" ) | replace "'" "\\'" ) | replace "," "\\," ) | replace "." "\\." ) | replace "/" "\\/" ) | replace "~" "\\~" ) | replace "!" "\\!" ) | replace "@" "\\@" ) | replace "#" "\\#" ) | replace "$" "\\$" ) | replace "%" "\\%" ) | replace "^" "\\^" ) | replace "&" "\\&" ) | replace "*" "\\*" ) | replace "(" "\\(" ) | replace ")" "\\)" ) | replace "_" "\\_" ) | replace "+" "\\+" ) | replace "{" "\\{" ) | replace "}" "\\}" ) | replace "|" "\\|" ) | replace ":" "\\:" ) | replace "\"" "\\\"" ) | replace "<" "\\<" ) | replace ">" "\\>" ) | replace "?" "\\?" ) }
.action{$Created := toDate "20060102150405" $created | date "2006-01-02 15:04:05"}
.action{$Updated := toDate "20060102150405" $updated | date "2006-01-02 15:04:05"}

| 标题  | .action{$Title} | ID  | .action{.id}      |
| :---: | :-------------- | :---: | :---------------- |
| 命名  | .action{$Name}  | 路径  | .action{$Hpath}   |
| 别名  | .action{$Alias} | 创建  | .action{$Created} |
| 备注  | .action{$Memo}  | 更新  | .action{$Updated} |

模板解析与渲染样式:

| 标题  | 外部网关协议                                            | ID  | 20211227165822-lqn27nn              |
| :---: | :------------------------------------------------------ | :---: | :---------------------------------- |
| 命名  | 外部网关协议                                            | 路径  | /计算机通信与网络/概念/外部网关协议 |
| 别名  | 外部路由器协议<br />EGP<br />ERP                        | 创建  | 2021-12-27 16:58:22                 |
| 备注  | External Gateway Protocol<br />External Router Protocol | 更新  | 2021-12-28 02:24:05                 |
标题 外部网关协议 ID 20211227165822-lqn27nn
命名 外部网关协议 路径 /计算机通信与网络/概念/外部网关协议
别名 外部路由器协议
EGP
ERP
创建 2021-12-27 16:58:22
备注 External Gateway Protocol
External Router Protocol
更新 2021-12-28 02:24:05
5 操作
shuoying 在 2022-01-08 01:04:51 更新了该帖
shuoying 在 2022-01-04 15:46:42 更新了该帖
shuoying 在 2021-12-31 15:29:29 更新了该帖
shuoying 在 2021-12-31 14:43:10 更新了该帖 shuoying 在 2021-12-31 14:28:27 更新了该帖

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • PiChou
    订阅者

    👍

  • 其他回帖
  • w345642713
    订阅者

    模板解析失败:template::27: unexpected "丨" in command

    1 回复
  • shuoying
    捐赠者 订阅者 作者

    文件保存时给自动格式化了, 已修复 🙏