Template Cheatsheet
Leave your common usage in the comment section below and we will add them to the list.
Authors
Get author shorthand
authors: <%= it.authorsShort %>
It will be rendered like Gerasimavicius et al.
.
Get author shorthand in annotation template
Info about parent literature are stored in it.docItem
.
from <%= it.docItem.authorsShort %>
Get List of Authors in Full Names
authors: [<%= it.authors %>]
Get List of Authors in first name or last name
authors: [<%= it.authors.map(v => v.firstName) %>]
# or
authors: [<%= it.authors.map(v => v.lastName) %>]
Do note that first name and last name are not always available.
Abstract
Get abstract in a single paragraph
## Abstract
<%= it.abstractNote.first().replace(/[\r\n]+/g, " ") %>
Tags
Include only manually created tags
To include only manually created tags, not the ones retrieved from literature, use the following code:
tags: [<%= it.tags.filter(t => t.type === 0) %>]
This is the default behavior before the change in v1.1.0.
In Zotero, manually created tags have value 0, while the ones retrieved from literature have value 1.
Date
Get when the literature was imported to Zotero
import-date: <%= it.dateAccessed %>
Get publish date
publish-date: <%= it.date %>
Collections
Get collections
collections: [<%= it.collections %>]
Get collection with full path
collections: [<%= it.collections.map(c => c.path) %>]
By default, the collection path is separated by >
, output like Collection 1 > Collection 2 > Collection 3
.
You can customize the separator by using join function.
The following code will output A/B/C
, similar to multi-level tags in Obsidian:
collections: [<%= it.collections.map(c => c.path.join("/")) %>]
Get top-level collections
top-collections: [<%= [...new Set(it.collections.map(c => c.path[0]))] %>]
Grouping
For details, see Object.groupBy (opens in a new tab) and Map.groupBy (opens in a new tab).
Group by annotation color
<% const byColor = Object.groupBy(it, (annot) => annot.colorName);
for (const color in byColor) { -%>
## <%= color %>
<%_ for (const annot of byColor[color]) { %>
<%~ include("annotation", annot) %>
<%_ } %>
<% } %>
Group by annotation color, customized label
<% const byColor = Object.groupBy(it, (annot) => annot.colorName);
const label = {
"red": "Important",
"orange": "Question",
"yellow": "Summary",
"gray": "Comment",
"green": "Answer",
"cyan": "Task",
"blue": "Fact",
"navy": "Definition",
"purple": "Quote",
"brown": "Source",
"magenta": "To Do",
};
// Merge colors with customized label with unexpected colors, if any
// Keep the order of the colors from the original color-label map
const colorSet = new Set([...Object.keys(label), ...Object.keys(byColor)]);
for (const color of colorSet) {
if (!(color in byColor)) continue -%>
### <%= label[color] ?? color %>
<%_ for (const annot of byColor[color]) { %>
<%~ include("annotation", annot) %>
<%_ } %>
<% } %>