The Codeblock Template plugin allows users to reuse the content of code blocks across multiple notes in Obsidian. It supports dynamic variables that can be interpolated into templates, enabling flexible customization. The plugin offers features like batch anonymous variables, array looping for repetitive content, and intuitive auto-completion when inserting templates. Templates are stored in a specified directory and can include placeholders for easy reuse. This plugin enhances efficiency by enabling centralized template management, making it ideal for users who frequently replicate structured code or note patterns.
一个可以把 Code Block 的内容在任何笔记中重复利用Obsidian模板插件!
,
分隔的多个值,避免为过多变量取名。(类似CSV语法) —— 2023年6月4日[1,2,3,4]
的array类型,可循环显示该行的内容。 —— 2023年6月12日...
或 ```pack-view,按下空格就可以自动补全完整的模板。 —— 2023年6月14日目前这个插件还没上传到 Obsidian 插件库,还需要手动安装。
main.js
和manifest.json
。codeblock-template
,并将 main.js 和 manifes.json 文件放入此文件夹即可。设置模板存放路径,默认路径为根目录的templates
。
创建模板
```pack-source a
# This is pack-source!
```
注意:要在设置中Template Source Path
指定的路径下创建才有效。
使用模板
```pack-view a
```
可以在创建模板时使用$.{}
来定义变量,在使用时传入变量。
```pack-source test1
Hello $.{name}!
```
通过key = value
或key = "value"
来定义变量。模板可以重复利用。
注意:为了方便存储,key 要符合标识符定义规则^1
```pack-view test1
name = "Super10"
```
---
```pack-view test1
name = "Sylcool"
```
匿名变量的前缀支持通过设置自定义,默认是anonymous_var_
。
注意:为了方便存储,key 要符合标识符定义规则^1
定义模板
```pack-source test_anonymous
| 1 | 2 | 3 | 4 | 5 |
| ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
| $.{anonymous_var_0} | $.{anonymous_var_1} | $.{anonymous_var_2} | $.{anonymous_var_3} | $.{anonymous_var_4} |
```
使用模板
```pack-view test_anonymous
value0,value1,value2,value4,....
```
定义
```pack-source test_loop
List:
1. $.{a}
```
使用
```pack-view test_loop
a = [A,B,C,D]
```
````pack-source dv
```dataview
LIST FROM "$.{path}"
```
````
````pack-source tasks
```tasks
not done
due after $.{date}
```
````