This documentation is like a dictionary. For beginners, see How to Use Templates.
Use Ctrl+F
to look up what you need and make your own template!
Some type of templates(Item) support stages.
Code wrapped inside the stage will be called at a specific time.
For example, the beforeloop
stage code:
// @beforeloop-begin
code;
// @beforeloop-end
stage | calling time |
---|---|
beforeloop | before entering the loop of items |
default | loop of items |
afterloop | after leaving the loop of items |
In other type of templates, the default stage is called.
variables: link: string, subNoteItem, noteItem
variables: subNoteItem, noteItem
variables: subNoteLines: string[], subNoteItem, noteItem
variables: annotationItem, topItem
variables: noteItem
variables: noteItem
The return value must be a JSON string.
variables: -
beforeloop stage: items, copyNoteImage, editor, sharedObj(for temporary variables, shared by all stages)
default stage: topItem, itemNotes, copyNoteImage, editor, sharedObj
afterloop stage: items, copyNoteImage, editor, sharedObj
Removed after v0.7.15+
Description: Normal line.
Template Type: None.
Required Variable: None.
<p>Your Line Here</p>
Description: From h1 to h6.
Template Type: None.
Required Variable: None.
<h1>Your Heding 1 Here</h1>
<h2>Your Heding 2 Here</h2>
Description: Highlight.
Template Type: None.
Required Variable: None.
<p style="background-color:#dbeedd;">Text</p>
Description: Strong text. Put it in a p
.
Template Type: None.
Required Variable: None.
<strong>Your Text</strong>
Description: Underline text. Put it in a p
.
Template Type: None.
Required Variable: None.
<u>Your Text</u>
Description: Deleteline text. Put it in a p
.
Template Type: None.
Required Variable: None.
<span style="text-decoration: line-through">Your Text</span>
Description: Link. Put it in a p
.
Template Type: None.
Required Variable: None.
<a href="zotero://replace/this/link">Link Text</a>
Description: Number List.
Template Type: None.
Required Variable: None.
<ol>
<li>First</li>
<li>Second</li>
<li>...</li>
</ol>
Description: Bullet List.
Template Type: None.
Required Variable: None.
<ul>
<li>First</li>
<li>Second</li>
<li>...</li>
</ul>
Description:
Template Type: None.
Required Variable: None.
<p>The<sup>sup</sup>and the<sub>sub</sub> text</p>
Description:
Block Quote
Template Type: None.
Required Variable: None.
<blockquote>
<p>Text</p>
</blockquote>
Description: Monospaced
Template Type: None.
Required Variable: None.
<pre>Text</pre>
Description:
Table | Column1 | Column2 |
---|---|---|
00 | 01 | 02 |
10 | 11 | 12 |
Template Type: None.
Required Variable: None.
<table>
<tr>
<th style="background-color:#dbeedd;">
<p style="text-align: right">Table</p>
</th>
<th style="background-color:#dbeedd;">Column1</th>
<th style="background-color:#dbeedd;">Column2</th>
</tr>
<tr>
<td>00</td>
<td>01</td>
<td>02</td>
</tr>
<tr>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</table>
Description: Current Date.
Required Variable: None.
<p>${new Date().toLocaleDateString()}</p>
Description: item.getTags()
returns tags in list. Usually use tags.includes("YourTag") ? do sth : do sth else
.
Required Variable: any item/note/annotation.
<p>${topItem.getTags()}</p>
Description: Note Title. First line of note.
Template Type: Note.
Required Variable: noteItem/subNoteItem.
<p>${noteItem.getNoteTitle()}</p>
Description: Note Content.
Template Type: Note.
Required Variable: noteItem/subNoteItem.
<p>${noteItem.getNote()}</p>
Description: Note Link.
Template Type: Note.
Required Variable: noteItem/subNoteItem.
<p>
<a href="${Zotero.BetterNotes.knowledge.getNoteLink(noteItem)}">
${noteItem.key}
</a>
</p>
Description: Item title.
Template Type: Item.
Required Variable: topItem.
<p>${topItem.getField("title")}</p>
Description: Publisher/Journal.
Template Type: Item.
Required Variable: topItem.
<p>
$
{(() => {
if (topItem.itemType === "conferencePaper") {
return;
topItem.getField("conferenceName") ||
topItem.getField("proceedingsTitle");
}
if (topItem.itemType === "journalArticle")
return topItem.getField("publicationTitle");
if (topItem.itemType === "report") return topItem.getField("institution");
return topItem.getField("publicationTitle");
})()}
</p>
Description: Authors.
Template Type: Item.
Required Variable: topItem.
<p>
$
{topItem
.getCreators()
.map((v) => v.firstName + " " + v.lastName)
.join("; ")}
</p>
Description: Pub. date.
Template Type: Item.
Required Variable: topItem.
<p>${topItem.getField("date")}</p>
Description: Publication date/time.
Template Type: Item.
Required Variable: topItem.
<p>${topItem.getField("date")}</p>
Description: DOI.
Template Type: Item.
Required Variable: topItem.
<p>
<a href="https://doi.org/${topItem.getField('DOI')}">
${topItem.getField("DOI")}
</a>
</p>
Description: URL.
Template Type: Item.
Required Variable: topItem.
<p>
<a href="${topItem.getField('url')}">${topItem.getField("url")}</a>
</p>
Description: CitationKey.
Template Type: Item.
Required Variable: topItem.
<p>${topItem.citationKey ? topItem.citationKey : ""}</p>
Description: URL.
Template Type: Item.
Required Variable: topItem.
<p>
$
{((topItem) => {
const getPDFLink = (_item) => {
let libraryID = _item.libraryID;
let library = Zotero.Libraries.get(libraryID);
let itemKey = _item.key;
let itemLink = "";
if (library.libraryType === "user") {
itemLink = `zotero://open-pdf/library/items/${itemKey}`;
} else if (library.libraryType === "group") {
itemLink = `zotero://open-pdf/groups/${library.id}/items/${itemKey}`;
}
return `<a href="${itemLink}">${_item.getFilename()}</a>`;
};
return Zotero.Items.get(topItem.getAttachments())
.filter((i) => i.isPDFAttachment())
.map((i) => getPDFLink(i))
.join("\n");
})(topItem)}
</p>
Description: Walk all sub notes under an item. You can add your code inside the loop.
Template Type: Item.
Required Variable: topItem.
${itemNotes.map((noteItem)=>{
// process each item note
const noteLine = `<blockquote>
${noteItem.getNote()}
</blockquote>`;
copyNoteImage(noteItem);
return noteLine;
}).join("\n")}
The noteItem
and topItem
is a Zotero Item object. The general data can be accessed using the getField()
method.
For example: topItem.getField('title')
will return the title of the topItem
.
// Get Item Fields
getField: (void)=>string;
// Get Authors
getCreators: (void)=>{
fieldMode: number,
firstName: string, // may be empty
lastName: string,
creatorTypeID: number,
}[];
Find available fields of the selected item with the code below:
const item = ZoteroPane.getSelectedItems().shift();
const usedFields = item.getUsedFields();
Zotero.ItemFields.getAll()
.filter((e) => usedFields.indexOf(e.id) >= 0)
.map((e) => e.name);
The result is like this (depending on the item you select):
[
"0": "title"
"1": "date"
"2": "language"
"3": "shortTitle"
"4": "libraryCatalog"
"5": "url"
"6": "accessDate"
"7": "pages"
"8": "conferenceName"
]
or see https://aurimasv.github.io/z2csl/typeMap.xml for the detailed Zotero fields documentation.