[Note Template] #619
Replies: 2 comments
-
Hi,
To run JS code in Zotero, open menu-> tools -> developers -> run javascript and paste the code there. Make sure a top-level item is selected in the library. const item = ZoteroPane.getSelectedItems().shift();
const usedFields = item.getUsedFields();
Zotero.ItemFields.getAll()
.filter((e) => usedFields.indexOf(e.id) >= 0)
.map((e) => e.name); The The selection syntax If you still encounter failures, please paste a screenshot of the library with the note selected, which fails with yaml header rendering when exported. |
Beta Was this translation helpful? Give feedback.
-
Hello Thanks very much for that!! I will try it out and let you know if I have any problems! Thanks for making this plug-in as well! It has saved me so much time since I started using it! |
Beta Was this translation helpful? Give feedback.
-
Template Type
MDFileheader
Desired Template Performance
Insert all details I want into notes metadata upon import to obsidian
Describe what you want.
I have tried the authors and creators fields but it always comes up black upon import and I am not sure how to do this with the noteItem.parentItem? noteItem.parentItem.getField format in the MDFileheader. The fields I have in my current template work, but the additional fields I have listed below I can seem to get to work. I have almost no knowledge of coding or this syntax and have tried numerous ways via trial and error and got some to work but the fields below are beyond my knowledge. Any help would be greatly appreciated
Additionally can you explain to me how you use this in that was in the templates guidance section
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"
]
Fields I want to add:
Authors (can't seem to get this to work)
$ {topItem .getCreators() .map((v) => v.firstName + " " + v.lastName) .join("; ")}
####The format for conditionals such as:
Journal
$ {(() => { 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"); })()}
Pdf link
$ {((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 `${_item.getFilename()}`; }; return Zotero.Items.get(topItem.getAttachments()) .filter((i) => i.isPDFAttachment()) .map((i) => getPDFLink(i)) .join("\n"); })(topItem)}
Current Template
Beta Was this translation helpful? Give feedback.
All reactions