Files
Capture/TEMPLATER.md
2026-02-24 10:33:48 +08:00

64 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Templater 使用指南
[Templater](https://silentvoid13.github.io/Templater/) 是 Obsidian 的模板插件,支持在模板中插入变量、执行 JavaScript,实现自动化创建笔记。
## 1. 初次配置
已在 `kb/.obsidian/plugins/templater-obsidian/data.json` 中预设模板文件夹为 `template`
1. 打开 Obsidian(以 `kb/` 为 vault)→ **设置****Templater**
2. 确认 **模板文件夹位置**`template`(即 `kb/template/`,相对 vault 根目录)
3. 若显示为空,请手动填入 `template` 并保存
4. (可选)勾选「在新标签页中打开新创建的笔记」
## 2. 基本用法
### 从模板创建新笔记
- **方式 A**:命令面板(`Ctrl/Cmd + P`)→ 输入 `Templater: Create new note from template` → 选择模板 → 选择存放位置
- **方式 B**:为常用模板设置快捷键(设置 → 热键 → 搜索 Templater
### 在现有文件中插入模板
- 命令面板 → `Templater: Insert template`
- 或在编辑器中输入 `<%` 触发内联 Templater 命令
## 3. 常用语法速查
| 语法 | 含义 |
|------|------|
| `<% tp.file.title %>` | 当前文件名(无扩展名) |
| `<% tp.file.creation_date("YYYY-MM-DD") %>` | 创建日期 |
| `<% tp.date.now("YYYY-MM-DD") %>` | 今天日期 |
| `<% tp.file.cursor() %>` | 插入后光标跳转到此处 |
| `<% await tp.system.prompt("输入角色名", "佩佩") %>` | 弹窗让用户输入 |
| `<%* // 代码块,不输出内容 %>` | 执行 JavaScript,无输出 |
### 与项目模板的对应关系
项目模板用 `{{name}}``{{title}}` 等占位符,Templater 可用以下替换:
| 占位符 | Templater 写法 |
|--------|----------------|
| `{{name}}` | `<% await tp.system.prompt("角色名称", "") %>``tp.file.title` |
| `{{title}}` | `<% await tp.system.prompt("Beat 标题", "") %>``tp.file.title` |
| `{{term_name}}` | `<% await tp.system.prompt("设定名称", "") %>``tp.file.title` |
## 4. 模板文件位置
- **Obsidian 内使用**`kb/template/`vault 内,Templater 可访问)
- **项目根目录**`template/`(与 `kb/` 同级,AI 创建文件时参考)
两份内容应保持一致,修改时请同步更新。
## 5. 推荐工作流
- **新建角色**`Templater: Create new note from template` → 选 `tpl-character.md` → 保存到 `kb/bible/角色/xxx.md`
- **新建 Beat**:同上 → 选 `tpl-beat.md` → 保存到 `kb/beats/场景-事件.md`
- **新建 Eureka**:选 `tpl-eureka.md` → 保存到 `inbox/xxx.md`
## 6. 官方文档
- [Templater 官方文档](https://silentvoid13.github.io/Templater/)
- [内置变量与函数](https://silentvoid13.github.io/Templater/Internal%20Variables/Internal%20Variables/)