Helper functions

To help you write your own templates in JavaScript, the extension provides helper functions via a global object - zoteroRoam. You may have come across them in the Getting Started section, in the code for the default formatting function.

All available functions are described below ; note that the arguments item, pdfs, and notes correspond to the arguments your custom function receives from the extension.

// Let's say you're writing a custom function called myFunction
// It will be passed 3 arguments by the extension, in order:
// - item: the raw metadata for the Zotero item
// - pdfs: the raw metadata for the PDF(s) linked to the Zotero item
// - notes: the raw metadata for the notes/annotations linked to the Zotero item

window.myFunction = function(item, pdfs, notes){
    let metadata = [];
    
    // Inside of your function, you can use helpers like so:
    metadata.push(`Type:: ` + zoteroRoam.getItemType(item));
    if(notes.length > 0){
        metadata.push({
            string: "[[Notes]]",
            children: zoteroRoam.formatNotes(notes)
        })
    }
    
    return metadata;
}

List of functions

chevron-rightzoteroRoam.formatNotes(notes)hashtag

Args

notes - the notes/annotations linked to the Zotero item

Returns

The notes/annotations, formatted according to current user settings.

Usage

chevron-rightzoteroRoam.formatPDFs(pdfs)hashtag

Args

pdfs - the PDFs linked to the Zotero item

as - the format in which to return the PDFs' information. Values: string|links|identity . Default : "string".

Returns

The list of PDFs, according to the configuration provided.

Usage

chevron-rightzoteroRoam.getItemChildren(item)hashtag

You normally won't need to use this method, since your function will receive the item's PDFs and notes/annotations as arguments.

Args

item - the Zotero item

Returns

An Array containing the raw metadata of all the item's linked PDFs, notes, and annotations.

Usage

chevron-rightasync zoteroRoam.getItemCitation(item)hashtag

Refer to the Zotero API documentationarrow-up-right for details and accepted values.

Args

item - the Zotero item

config - additional configuration Object. Properties available :

  • style - the citation style to use. Default : "chicago-note-bibliography".

  • locale - the locale to use when generating the citation. Default : "en-US".

  • linkwrap - whether URLs and DOIs should render as links. Values : 0|1. Default : 0.

Returns

A formatted citation for the item, according to the configuration provided.

Usage

chevron-rightzoteroRoam.getItemCollections(item)hashtag

Args

item - the Zotero item

config - additional configuration Object. Properties available:

  • brackets : whether to surround the collection names in brackets. Values: true|false. Default : true.

  • return_as : the format in which the collection names should be returned. Values: "string"|"array". Default: "string".

Returns

The names of the item's Zotero collections, formatted according to the configuration provided.

Usage

chevron-rightzoteroRoam.getItemCreators(item)hashtag

Args

item - the Zotero item

config - additional configuration Object. Properties available:

  • brackets : whether to surround the creator names in brackets. Values: true|false|existing. Default : true.

  • return_as : the format in which the creators should be returned. Values: "string"|"array"|"identity". Default: "string".

  • use_type : whether to include the creator's type (author, editor, ...). Values: true|false. Default : true.

Returns

The creators of the Zotero item, formatted according to the configuration provided.

Usage

chevron-rightzoteroRoam.getItemDateAdded(item)hashtag

Args

item - the Zotero item

config - additional configuration Object. Properties available:

  • brackets : whether to surround the date with brackets. Values : true|false. Default : true.

Returns

The date on which the item was added to Zotero, in Daily Notes Page format.

Usage

chevron-rightzoteroRoam.getItemMetadata(item, pdfs, notes)hashtag

Args

item - the Zotero item

pdfs - the Zotero item's linked PDFs

notes - the Zotero item's linked notes/annotations

Returns

The output of the extension's default metadata formatter, according to current user settings.

Usage

chevron-rightzoteroRoam.getItemPublication(item)hashtag

Args

item - the Zotero item

config - additional configuration Object. Properties available :

  • brackets - whether to surround the publication with brackets. Values : true|false. Default : true.

Returns

The publication details of the item. In order, the extension will look for a publicationTitle, then a bookTitle, then a university name.

Usage

chevron-rightzoteroRoam.getItemRelated(item)hashtag

Args

item - the Zotero item

config - additional configuration Object. Properties available :

  • brackets - whether to surround the relations with brackets. Values : true|false. Default : true.

  • return_as - the format in which to return the relations. Values : string|array|raw. Default : "string".

Returns

The list of Zotero items related to the given item, per Zotero metadata.

Usage

chevron-rightzoteroRoam.getItemTags(item)hashtag

Args

item - the Zotero item

config - additional configuration Object. Properties available:

  • brackets - whether to surround the tags with brackets. Values : true|false. Default : true.

  • return_as - the format in which to return the tags. Values : string|array. Default : string.

Returns

The tags of the item

Usage

chevron-rightzoteroRoam.getItemType(item)hashtag

Args

item - the Zotero item

config - additional configuration Object. Properties available :

  • brackets - whether to surround the type with brackets. Values : true|false. Default : true.

Returns

The item's type, according to current user settings (mapping provided in Typemap).

Usage

Last updated

Was this helpful?