跳到主要内容

模板变量与默认模板

每种模板类型暴露自己的 context 变量。本页是完整参考——四种模板类型的全部变量表,以及可作为起点的内置默认模板。语法与工作流见模板指南;filter 见模板 Filter 参考

1. Zotero Source Note 模板

控制 Zotero 库条目的 Source Note 正文。context 为 { item, settings }

item — Zotero 条目

变量类型说明
item.keystringZotero item key
item.versionnumber条目版本号,用于增量更新检测
item.libraryIDnumber库 ID
item.citationKeystringCitation key(如 Better BibTeX 生成),未设置则为空串
item.itemTypestring条目类型("journalArticle""book" 等)
item.titlestring标题
item.parentItemstring父条目 key;顶层条目为空串
item.creatorsArray<{ name: string }>作者列表,name 为组合后的全名
item.datestring | null出版日期字符串(Zotero 中填写的原始值)
item.yearstring | null从 date 提取的四位年份(如 date 为 "2024-05-01" 则 year 为 "2024",date 为空或格式不规范则 year 也为 null)
item.dateAddedstringISO 时间戳,条目添加到 Zotero 的时间
item.dateModifiedstringISO 时间戳,最后修改时间
item.accessDatestring | null最后访问日期
item.abstractNotestring | undefined摘要
item.publicationTitlestring | undefined期刊/会议名
item.publisherstring | undefined出版社
item.placestring | undefined出版地
item.volumestring | undefined
item.issuestring | undefined
item.pagesstring | undefined页码范围
item.seriesstring | undefined系列名
item.seriesNumberstring | undefined系列编号
item.editionstring | undefined版次
item.urlstring | undefinedURL
item.DOIstring | undefinedDOI
item.ISBNstring | undefinedISBN
item.ISSNstring | undefinedISSN
item.tagsArray<{ tag, type? }>标签列表
item.itemPathsstring[]条目所在的 collection 路径数组(如 ["Research/ML"]
item.attachmentsAttachmentContext[]子附件列表(PDF 等)
item.annotationsAnnotationContext[]直接在条目上的 annotation(仅 standalone attachment 条目有)
item.attachmentAnnotationsAnnotationContext[]所有 attachment 下 annotation 的扁平汇总
item.notesNoteContext[]Zotero 子笔记列表
item.relatedItemsRelatedItemContext[]Zotero "Related" 关联条目列表

item.attachments[] — 附件子对象

变量类型说明
attachment.keystringAttachment item key
attachment.libraryIDnumber库 ID
attachment.parentItemstring所属顶层条目的 key
attachment.filenamestring文件名(如 "paper.pdf"
attachment.contentTypestringMIME 类型(如 "application/pdf"
attachment.tagsArray<{ tag, type? }>标签
attachment.dateAddedstringISO 时间戳
attachment.dateModifiedstringISO 时间戳
attachment.annotationsAnnotationContext[]该附件上的 annotation 列表

item.notes[] — 子笔记

变量类型说明
note.keystringNote item key
note.libraryIDnumber库 ID
note.titlestring笔记标题(首行或空)
note.parentItemstring父条目 key
note.notestring笔记完整 HTML(Zotero ProseMirror 格式)
note.tagsArray<{ tag, type? }>标签
note.dateAddedstringISO 时间戳
note.dateModifiedstringISO 时间戳

item.relatedItems[] — 关联条目

来自 Zotero 的 Related 标签页(dc:relation)。每条记录对应一个关联 URI。keylibraryID 始终从 URI 解析得到;其余字段仅在关联条目已存在于本地数据库时才填充。

变量类型说明
rel.keystring关联条目的 Zotero item key
rel.libraryIDnumber从 relation URI 解析的库 ID
rel.resolvedboolean条目是否在本地数据库中(false 表示跨库/未同步/已删除)
rel.titlestring | undefined标题(仅 resolved 时)
rel.itemTypestring | undefined条目类型(仅 resolved 时)
rel.citationKeystring | undefinedCitation key(仅 resolved 时)
rel.notePathstring | undefined该条目 Source Note 在 vault 中的路径(仅 resolved 时)

跨库或未同步的关联条目仍会出现在列表中(resolved: false),可用于占位提示。用 {% if rel.resolved %}{% if rel.title %} 过滤。

item.annotations[] / attachment.annotations[] — Annotation

变量类型说明
annotation.keystringAnnotation item key
annotation.libraryIDnumber库 ID
annotation.parentItemstring | undefined所属附件的 key
annotation.typestring类型:"highlight""note""image""ink"
annotation.authorNamestring | undefined批注作者
annotation.textstring | null高亮文本(>< 已转义)
annotation.commentstring | undefined批注评论(已转 Markdown:<b>**<i>*<sub>/<sup> 保留 inline HTML)
annotation.colorstring | undefined十六进制颜色(如 "#ffd400"
annotation.pageLabelstring | undefined页码标签
annotation.tagsArray<{ tag, type? }>标签
annotation.dateAddedstringISO 时间戳
annotation.dateModifiedstringISO 时间戳
annotation.rawAnnotationJSON原始 annotation 对象,配合 process_nav_info filter 使用

settings — 插件配置

ZotFlowSettings 全量暴露,常用:

变量类型说明
settings.annotationImageFolderstring批注图片输出目录
settings.sourceNoteFolderstring默认 Source Note 目录

默认模板

不配置自定义模板时使用以下 built-in 模板:

---
citationKey: {{ item.citationKey | json }}
title: {{ item.title | json }}
itemType: {{ item.itemType | json }}
creators: [{% for c in item.creators %}"{{ c.name }}"{% unless forloop.last %}, {% endunless %}{% endfor %}]
publication: {{ item.publicationTitle | default: item.publisher | json }}
date: {{ item.date | json }}
year: {{ item.year }}
url: {{ item.url | json }}
doi: {{ item.DOI | json }}
tags: [{% for t in item.tags %}"#{{ t.tag | replace: " ", "_" }}"{% unless forloop.last %}, {% endunless %}{% endfor %}]
---
{%- capture quote_string %}{{ newline }}> {% endcapture -%}
{%- capture quote_string_2 %}{{ newline }}> >{% endcapture -%}
# {{ item.title }}
{%- if item.abstractNote -%}
## Abstract
> {{ item.abstractNote | replace: newline, quote_string }}

{%- endif -%}
{%- if item.attachments.length > 0 -%}
## Attachments
{%- for attachment in item.attachments -%}
- [{{ attachment.filename }}]({{ attachment | attachment_link }})
{%- endfor -%}

{%- endif -%}
## Notes
{%- if item.notes.length > 0 -%}
{%- for note in item.notes -%}
{{ note.note | html2md | wrap_editable: "NOTE", note.key }}

{%- endfor -%}
{%- endif -%}
{%- if item.attachments.length > 0 and item.attachmentAnnotations.length > 0 -%}
## Annotations
{%- for attachment in item.attachments -%}
{%- if attachment.annotations.length > 0 -%}
### {{ attachment.filename }}
{%- for annotation in attachment.annotations -%}
> [!zotflow-{{ annotation.type }}-{{ annotation.color }}] [{{ attachment.filename }}, p.{{ annotation.pageLabel }}]({{ annotation | annotation_link }})
{%- if annotation.type == "ink" or annotation.type == "image"-%}
> > ![[{{settings.annotationImageFolder}}/{{ annotation.key }}.png]]
{%- else -%}
> > {{ annotation.text | replace: newline, quote_string_2 }}
{%- endif -%}
>
> {{ annotation.comment | wrap_editable: "ANNO", annotation.key | replace: newline, quote_string }}
> {% if annotation.tags and annotation.tags.length > 0 -%} {% for t in annotation.tags %}#{{ t.tag | replace: " ", "_" }}{% unless forloop.last %} {% endunless %}{% endfor %} {%- endif %}
^{{ annotation.key }}

{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- if item.attachments.length == 0 and item.itemType == "attachment" and item.annotations.length > 0 -%}
## Annotations
{%- for annotation in item.annotations -%}
> [!zotflow-{{ annotation.type }}-{{ annotation.color }}] [{{ item.title }}, p.{{ annotation.pageLabel }}]({{ annotation | annotation_link }})
{%- if annotation.type == "ink" or annotation.type == "image"-%}
> > ![[{{settings.annotationImageFolder}}/{{ annotation.key }}.png]]
{%- else -%}
> > {{ annotation.text | replace: newline, quote_string_2 }}
{%- endif -%}
>
> {{ annotation.comment | wrap_editable: "ANNO", annotation.key | replace: newline, quote_string }}
> {% if annotation.tags and annotation.tags.length > 0 -%} {% for t in annotation.tags %}#{{ t.tag | replace: " ", "_" }}{% unless forloop.last %} {% endunless %}{% endfor %} {%- endif %}
^{{ annotation.key }}

{%- endfor -%}
{%- endif -%}
  1. frontmatter — 输出 citationKeytitleitemTypecreatorspublicationdateyearurldoitags
  2. 标题# 标题
  3. 摘要 — 以 blockquote 格式渲染
  4. 附件 — 可点击链接列表(通过 attachment_link filter,默认在 ZotFlow reader 中打开)
  5. 子笔记 — 每个 note 通过 html2md | wrap_editable 渲染为 editable region
  6. 批注 — 按 attachment 分组,使用 [!zotflow-<type>-<color>] callout 渲染,annotation comment 包裹为 editable region,标签在评论下方独立行显示

2. Local Source Note 模板

控制 vault 内本地文件(PDF/EPUB/HTML)的 Source Note。context 为 { item, settings, path }

item — 本地文件

变量类型说明
item.namestring完整文件名(如 "paper.pdf"
item.pathstringvault 相对路径(如 "Articles/paper.pdf"
item.extensionstring扩展名(如 "pdf"
item.basenamestring不含扩展名的文件名(如 "paper"
item.annotationsLocalAnnotation[]本地 reader 产生的 annotation 列表

item.annotations[] — 本地 Annotation

变量类型说明
annotation.keystringAnnotation ID
annotation.libraryIDnumber始终为 0(本地文件)
annotation.typestring"highlight""note""image""ink"
annotation.authorNamestring | undefined批注作者
annotation.textstring | null高亮文本
annotation.commentstring | undefined用户评论
annotation.colorstring | undefined颜色
annotation.pageLabelstring | undefined页码
annotation.tagsArray<{ tag, type? }>标签
annotation.dateAddedstring | undefinedISO 时间戳
annotation.dateModifiedstring | undefinedISO 时间戳
annotation.rawAnnotationJSON原始对象,配合 process_raw_anno_json filter

path / settings

  • path — 同 item.path
  • settings — 与 Zotero 模板共享同一 ZotFlowSettings 对象

默认模板

输出逻辑与 Zotero 模板类似但更精简:无元数据字段(本地文件没有 Zotero 元数据),只输出标题与 annotation 列表。annotation 评论以可编辑区形式包裹——在 note 中的编辑会回写到 .zf.json sidecar。wrap_editable(包括 "PERSIST" 区域)同样适用于本地模板;只读/外部 annotation 会自动渲染为普通锁定文本。

---
zotflow-locked: {{true}}
zotflow-local-attachment: [[{{ path }}]]
---
{%- capture quote_string %}{{ newline }}> {% endcapture -%}
{%- capture quote_string_2 %}{{ newline }}> >{% endcapture -%}
# {{ item.basename }}
{%- if item.annotations.length > 0 -%}
## Annotations
{%- for annotation in item.annotations -%}

> [!zotflow-{{ annotation.type }}-{{ annotation.color }}] [[{{item.path}}#page={{ annotation.pageLabel }}#annotation={{ annotation.key | process_nav_info }}|{{ item.name }}, p.{{ annotation.pageLabel }}]]
{%- if annotation.type == "ink" or annotation.type == "image"-%}
> > ![[{{settings.annotationImageFolder}}/{{ annotation.key }}.png]]
{%- else -%}
> > {{ annotation.text | replace: newline, quote_string_2 }}
{%- endif -%}
>
> {{ annotation.comment | wrap_editable: "ANNO", annotation.key | replace: newline, quote_string }}
{%- if annotation.tags and annotation.tags.length > 0 -%}
>
> {% for t in annotation.tags %}#{{ t.tag | replace: " ", "_" }}{% unless forloop.last %} {% endunless %}{% endfor %}
{%- endif -%}
^{{ annotation.key }}

{%- endfor -%}
{%- endif -%}

3. Citation 模板

控制引用插入的渲染输出。共五个 slot:

Slot输出物触发场景
Pandoc[@key] 格式引用拖拽/建议框/复制时选 Pandoc
Wikilink[[notePath|label]] 格式链接拖拽/建议框/复制时选 Wikilink
Footnote Reference行内 [^key] 标记Footnote 引用的行内部分
Footnote Definition文档末尾的脚注定义Footnote 引用的定义部分
Citekey@key不经过模板渲染,直接输出

Citation Context 变量

变量类型说明
item.keystringZotero item key
item.citationKeystringCitation key(空串回退到 item.key
item.titlestring标题
item.creatorsArray<{ name }>作者列表
item.datestring出版日期
item.itemTypestring条目类型
item.urlstring | undefinedURL
item.DOIstring | undefinedDOI
item.publicationTitlestring | undefined期刊/会议名
item.publisherstring | undefined出版社
item.volumestring | undefined
item.issuestring | undefined
item.pagesstring | undefined页码
item.tagsArray<{ tag }>标签
item.*Zotero item 的其他字段同样可用
notePathstringSource Note 在 vault 中的相对路径
annotationsArray当前选中的 annotation 列表(无选中时为空数组)

annotations[] 子字段:annotation.keyannotation.typeannotation.textannotation.commentannotation.colorannotation.pageLabelannotation.tagsannotation.dateAddedannotation.dateModified

annotations.size 判断是否有选中 annotation,用 annotations | map: 'pageLabel' 提取页码。

默认 Citation 模板

Pandoc:

[@{{ item.citationKey | default: item.key }}{% if annotations.size > 0 %}{% assign pages = annotations | map: 'pageLabel' | compact | uniq | join: ', ' %}{% if pages != empty %}, pp. {{ pages }}{% endif %}{% endif %}]

输出示例:[@smith2024, pp. 3, 7]

Footnote Reference:

[^{{ item.citationKey | default: item.key }}]

输出示例:[^smith2024]

Footnote Definition:

[^{{ item.citationKey | default: item.key }}]: {%- if item.creators.length > 1 -%}
{{ item.creators[0].name }} et al.
{%- elsif item.creators.length == 1 -%}
{{ item.creators[0].name }}
{%- else -%}
Unknown Author
{%- endif -%}, *{{ item.title }}* ({{ item.date | slice: 0, 4 }}).

输出示例:Smith et al., *Deep Learning for NLP* (2024).

Wikilink:

{%- if annotations.size > 0 -%}
{%- for annotation in annotations -%}
[[{{ notePath }}#^{{ annotation.key }}|{{ item.creators[0].name | default: "Unknown" }} ({{ item.date | slice: 0, 4 }}), p. {{ annotation.pageLabel }}]]
{%- if forloop.last == false %}, {% endif -%}
{%- endfor -%}
{%- else -%}
[[{{ notePath }}|{{ item.creators[0].name | default: "Unknown" }} ({{ item.date | slice: 0, 4 }})]]
{%- endif -%}

4. Path 模板

控制 Source Note 文件在 vault 中的落点路径。每段路径名会自动 sanitize(去除非法字符、处理保留名)。

Library Path 变量

变量类型说明
keystringZotero item key
citationKeystringCitation key
libraryIDnumber库 ID
itemTypestring条目类型
titlestring标题
creatorsArray<{ name }>作者列表
datestring出版日期
yearstring从 date 提取的四位年份
libraryNamestring库显示名称
publicationTitlestring期刊/会议名
publisherstring出版社
tagsArray<{ tag }>标签
itemPathsstring[]Collection 路径
*其他 Zotero 元数据字段同样可用

Local Path 变量

变量类型说明
basenamestring无扩展名的文件名
namestring完整文件名
pathstringvault 相对路径
extensionstring扩展名(不含点)

默认 Path 模板

Library: Source/{{libraryName}}/@{{citationKey | default: title | default: key}} 输出示例:Source/My Library/@smith2024

Local: Source/Local/@{{basename}} 输出示例:Source/Local/@myPaper

Path 模板建议

  • / 创建目录层级:References/{{year}}/{{citationKey}}
  • @ 前缀是视觉约定(区分 Source Note 与普通笔记),非强制
  • | default: 链式回退:{{citationKey | default: title | default: key}}
  • Collection 路径:{{itemPaths[0]}} 取首个 collection 路径


相关页面