3.3 Creating your own formatting functions
How to define custom functions & assign them to item types
Last updated
Was this helpful?
How to define custom functions & assign them to item types
Last updated
Was this helpful?
Custom functions must be defined with the syntax window.myFuncName = function(item) { ... }
rather than function myFuncName(item){ ... }
, otherwise an error will be thrown. This syntax is needed to make the function globally available, so that it can be found by the extension.
All formatting functions must do the following :
The function must take a single argument - the item's data object, as returned by the Zotero Web API. See here for an official gist from the Zotero API docs, showing an example object returned for a single item.
The function must return a single array - specifying the contents of the blocks that should be added to the item's page in Roam.
Each element of the array will be processed as a top-level Roam block to be added to the item's Roam page. If the element is a String of text, the block will be childless. If the element is an Object, it can have children blocks (see Nesting metadata).
String elements will be added as top-level, childless blocks.
Object elements will be processed recursively and support nested blocks.
The ordering of the blocks in Roam will reflect the ordering of the array.
To help you with writing your own functions, I've made an Observable interactive notebook, where you can try your hand at writing functions & using them to process your own Zotero data :
Custom functions can be assigned to item types using funcmap. You can assign a function to specific item types, or set it as the default formatting function.
Assigning the customPaperFormat
function to be used for conference papers and journal articles, and letting the extension handle other item types with its own defaults.
Using the customPaperFormat
function for all item types
Coming soon -- examples from the community will be posted here, as people share them !