Obsidian Bases Skill
Workflow
- 1. Create the file: Create a
.base file in the vault with valid YAML content - Define scope: Add
filters to select which notes appear (by tag, folder, property, or date) - Add formulas (optional): Define computed properties in the
formulas section - Configure views: Add one or more views (
table, cards, list, or map) with order specifying which properties to display - Validate: Verify the file is valid YAML with no syntax errors. Check that all referenced properties and formulas exist. Common issues: unquoted strings containing special YAML characters, mismatched quotes in formula expressions, referencing
formula.X without defining X in INLINECODE10 - Test in Obsidian: Open the
.base file in Obsidian to confirm the view renders correctly. If it shows a YAML error, check quoting rules below
Schema
Base files use the .base extension and contain valid YAML.
CODEBLOCK0
Filter Syntax
Filters narrow down results. They can be applied globally or per-view.
Filter Structure
CODEBLOCK1
Filter Operators
| Operator | Description |
|---|
| INLINECODE13 | equals |
| INLINECODE14 |
not equal |
|
> | greater than |
|
< | less than |
|
>= | greater than or equal |
|
<= | less than or equal |
|
&& | logical and |
|
\|\| | logical or |
|
! | logical not |
Properties
Three Types of Properties
- 1. Note properties - From frontmatter:
note.author or just INLINECODE22 - File properties - File metadata:
file.name, file.mtime, etc. - Formula properties - Computed values: INLINECODE25
File Properties Reference
| Property | Type | Description |
|---|
| INLINECODE26 | String | File name |
| INLINECODE27 |
String | File name without extension |
|
file.path | String | Full path to file |
|
file.folder | String | Parent folder path |
|
file.ext | String | File extension |
|
file.size | Number | File size in bytes |
|
file.ctime | Date | Created time |
|
file.mtime | Date | Modified time |
|
file.tags | List | All tags in file |
|
file.links | List | Internal links in file |
|
file.backlinks | List | Files linking to this file |
|
file.embeds | List | Embeds in the note |
|
file.properties | Object | All frontmatter properties |
The this Keyword
- - In main content area: refers to the base file itself
- When embedded: refers to the embedding file
- In sidebar: refers to the active file in main content
Formula Syntax
Formulas compute values from properties. Defined in the formulas section.
CODEBLOCK2
Key Functions
Most commonly used functions. For the complete reference of all types (Date, String, Number, List, File, Link, Object, RegExp), see FUNCTIONS_REFERENCE.md.
| Function | Signature | Description |
|---|
| INLINECODE41 | INLINECODE42 | Parse string to date (YYYY-MM-DD HH:mm:ss) |
| INLINECODE44 |
now(): date | Current date and time |
|
today() |
today(): date | Current date (time = 00:00:00) |
|
if() |
if(condition, trueResult, falseResult?) | Conditional |
|
duration() |
duration(string): duration | Parse duration string |
|
file() |
file(path): file | Get file object |
|
link() |
link(path, display?): Link | Create a link |
Duration Type
When subtracting two dates, the result is a Duration type (not a number).
Duration Fields: duration.days, duration.hours, duration.minutes, duration.seconds, INLINECODE60
IMPORTANT: Duration does NOT support .round(), .floor(), .ceil() directly. Access a numeric field first (like .days), then apply number functions.
CODEBLOCK3
Date Arithmetic
CODEBLOCK4
View Types
Table View
CODEBLOCK5
Cards View
CODEBLOCK6
List View
CODEBLOCK7
Map View
Requires latitude/longitude properties and the Maps community plugin.
CODEBLOCK8
Default Summary Formulas
| Name | Input Type | Description |
|---|
| INLINECODE65 | Number | Mathematical mean |
| INLINECODE66 |
Number | Smallest number |
|
Max | Number | Largest number |
|
Sum | Number | Sum of all numbers |
|
Range | Number | Max - Min |
|
Median | Number | Mathematical median |
|
Stddev | Number | Standard deviation |
|
Earliest | Date | Earliest date |
|
Latest | Date | Latest date |
|
Range | Date | Latest - Earliest |
|
Checked | Boolean | Count of true values |
|
Unchecked | Boolean | Count of false values |
|
Empty | Any | Count of empty values |
|
Filled | Any | Count of non-empty values |
|
Unique | Any | Count of unique values |
Complete Examples
Task Tracker Base
CODEBLOCK9
Reading List Base
CODEBLOCK10
Daily Notes Index
CODEBLOCK11
Embedding Bases
Embed in Markdown files:
CODEBLOCK12
YAML Quoting Rules
- - Use single quotes for formulas containing double quotes: INLINECODE80
- Use double quotes for simple strings: INLINECODE81
- Escape nested quotes properly in complex expressions
Troubleshooting
YAML Syntax Errors
Unquoted special characters: Strings containing :, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, ` ` must be quoted.
CODEBLOCK13
**Mismatched quotes in formulas**: When a formula contains double quotes, wrap the entire formula in single quotes.
CODEBLOCK14
### Common Formula Errors
**Duration math without field access**: Subtracting dates returns a Duration, not a number. Always access .days, .hours, etc.
CODEBLOCK15
**Missing null checks**: Properties may not exist on all notes. Use if() to guard.
CODEBLOCK16
**Referencing undefined formulas**: Ensure every formula.X in order or properties has a matching entry in formulas`.
CODEBLOCK17
References
Obsidian Bases 技能
工作流程
- 1. 创建文件:在仓库中创建一个包含有效 YAML 内容的 .base 文件
- 定义范围:添加 filters 来选择显示哪些笔记(按标签、文件夹、属性或日期)
- 添加公式(可选):在 formulas 部分定义计算属性
- 配置视图:添加一个或多个视图(table、cards、list 或 map),使用 order 指定要显示的属性
- 验证:确认文件是有效的 YAML 且没有语法错误。检查所有引用的属性和公式是否存在。常见问题:包含特殊 YAML 字符的未加引号字符串、公式表达式中引号不匹配、在 formulas 中未定义 X 却引用了 formula.X
- 在 Obsidian 中测试:在 Obsidian 中打开 .base 文件,确认视图正确渲染。如果显示 YAML 错误,请检查下面的引号规则
模式
Base 文件使用 .base 扩展名,并包含有效的 YAML。
yaml
全局过滤器适用于 base 中的所有视图
filters:
# 可以是单个过滤器字符串
# 或者是包含 and/or/not 的递归过滤器对象
and: []
or: []
not: []
定义可在所有视图中使用的公式属性
formulas:
formula_name: expression
配置属性的显示名称和设置
properties:
property_name:
displayName: 显示名称
formula.formula_name:
displayName: 公式显示名称
file.ext:
displayName: 扩展名
定义自定义汇总公式
summaries:
custom
summaryname: values.mean().round(3)
定义一个或多个视图
views:
- type: table | cards | list | map
name: 视图名称
limit: 10 # 可选:限制结果数量
groupBy: # 可选:分组结果
property: property_name
direction: ASC | DESC
filters: # 视图特定的过滤器
and: []
order: # 按顺序显示的属性
- file.name
- property_name
- formula.formula_name
summaries: # 将属性映射到汇总公式
property_name: Average
过滤器语法
过滤器用于缩小结果范围。它们可以全局应用或按视图应用。
过滤器结构
yaml
单个过滤器
filters: status == done
AND - 所有条件必须为真
filters:
and:
- status == done
- priority > 3
OR - 任一条件为真即可
filters:
or:
- file.hasTag(book)
- file.hasTag(article)
NOT - 排除匹配项
filters:
not:
- file.hasTag(archived)
嵌套过滤器
filters:
or:
- file.hasTag(tag)
- and:
- file.hasTag(book)
- file.hasLink(Textbook)
- not:
- file.hasTag(book)
- file.inFolder(必读)
过滤器运算符
不等于 |
| > | 大于 |
| < | 小于 |
| >= | 大于或等于 |
| <= | 小于或等于 |
| && | 逻辑与 |
| \|\| | 逻辑或 |
|
! | 逻辑非 |
属性
三种属性类型
- 1. 笔记属性 - 来自前置元数据:note.author 或直接 author
- 文件属性 - 文件元数据:file.name、file.mtime 等
- 公式属性 - 计算值:formula.my_formula
文件属性参考
| 属性 | 类型 | 描述 |
|---|
| file.name | 字符串 | 文件名 |
| file.basename |
字符串 | 不带扩展名的文件名 |
| file.path | 字符串 | 文件的完整路径 |
| file.folder | 字符串 | 父文件夹路径 |
| file.ext | 字符串 | 文件扩展名 |
| file.size | 数字 | 文件大小(字节) |
| file.ctime | 日期 | 创建时间 |
| file.mtime | 日期 | 修改时间 |
| file.tags | 列表 | 文件中的所有标签 |
| file.links | 列表 | 文件中的内部链接 |
| file.backlinks | 列表 | 链接到此文件的文件 |
| file.embeds | 列表 | 笔记中的嵌入内容 |
| file.properties | 对象 | 所有前置元数据属性 |
this 关键字
- - 在主内容区域:指 base 文件本身
- 嵌入时:指嵌入文件
- 在侧边栏中:指主内容中的活动文件
公式语法
公式根据属性计算值。在 formulas 部分定义。
yaml
formulas:
# 简单算术
total: price * quantity
# 条件逻辑
status_icon: if(done, ✅, ⏳)
# 字符串格式化
formatted_price: if(price, price.toFixed(2) + 美元)
# 日期格式化
created: file.ctime.format(YYYY-MM-DD)
# 计算创建以来的天数(使用 .days 获取 Duration)
days_old: (now() - file.ctime).days
# 计算距离截止日期的天数
daysuntildue: if(duedate, (date(duedate) - today()).days, )
关键函数
最常用的函数。有关所有类型(日期、字符串、数字、列表、文件、链接、对象、正则表达式)的完整参考,请参见 FUNCTIONS_REFERENCE.md。
| 函数 | 签名 | 描述 |
|---|
| date() | date(string): date | 将字符串解析为日期(YYYY-MM-DD HH:mm:ss) |
| now() |
now(): date | 当前日期和时间 |
| today() | today(): date | 当前日期(时间 = 00:00:00) |
| if() | if(condition, trueResult, falseResult?) | 条件判断 |
| duration() | duration(string): duration | 解析持续时间字符串 |
| file() | file(path): file | 获取文件对象 |
| link() | link(path, display?): Link | 创建链接 |
Duration 类型
当两个日期相减时,结果是 Duration 类型(不是数字)。
Duration 字段: duration.days、duration.hours、duration.minutes、duration.seconds、duration.milliseconds
重要提示: Duration 不直接支持 .round()、.floor()、.ceil()。请先访问数字字段(如 .days),然后应用数字函数。
yaml
正确:计算日期之间的天数
(date(due_date) - today()).days # 返回天数
(now() - file.ctime).days # 创建以来的天数
(date(due_date) - today()).days.round(0) # 四舍五入后的天数
错误 - 会导致错误:
((date(due) - today()) / 86400000).round(0) # Duration 不支持除法后再四舍五入
日期算术
yaml
持续时间单位:y/年、M/月、d/天、
w/周、h/小时、m/分钟、s/秒
now() + \1 day\ # 明天
today() + \7d\ # 从今天起一周
now() - file.ctime # 返回 Duration
(now() - file.ctime).days # 获取天数(数字)
视图类型
表格视图
yaml
views:
- type: table
name: 我的表格
order:
- file.name
- status
- due_date
summaries:
price: Sum
count: Average
卡片视图
yaml
views:
- type: cards
name: 画廊
order:
- file.name
- cover_image
- description
列表视图
y