Fix some issues with my template so as to effectively use the Zotero integrator plugin.
I am new to Obsidian and Bibtext, but I’m slowly teaching myself. However, I’m now finding I spend way more time setting up / adjusting Obsidian than actually using it. I would be grateful if the good folk in this forum could help me out… I need to get productive!
I have a Literature Note template with bibliographic data at the top and annotations underneath, grouped into headings based on the zotero highlighter color. I have used a range of online sources to develop my template, including Danny Hartcher’s guide for the annotations, which was very useful. However, I cannot resolve the following:
- List the collection names associated with the source (like tags, separated by a comma).
- Get the ‘journal article’ item type to display with a space between the two words.
- Make it so that headings in the template are collapsed by default.
- Format the callouts in the annotations so that they are coloured.
Things I have tried
- I have tried a range of different functions, including: {{collections}}, {{itemcollections}}, {{item.collections}}, {{collections | name}}, {{item.collections | name}}, {{item.collectionsn}}, {{item.collections0name}}. When I used the data explorer, I can see that the collections section has additional fields (a number, full path, key, and name) but I can’t figure out how to use these terms to get it to work. Everything I’ve tried either results in a blank output for that function, or an export error.
When I use {{collections}} it renders [object Object] that are formatted like hyperlinks, but don’t go anywhere. - I am currently using {{itemType | lower}}, but I honestly have no idea how to enforce the space. Tried searching on google, reddit, here etc., but can’t figure it out.
- I tried ensuring the headings are collapsed in the template, but I don’t know of any code etc. to make this work. I think the code for the annotations is forcing the sections open on import.
- I found the below CSS snippet on here, but I can’t remember who posted it sorry. I went down a massive rabbit hole with all of this and just kept trying so many different things. I adjusted the hex codes to match the Zotero highlighter codes (and thus the base code from Danny Hartcher) but it didn’t do anything.
I also have the admonitions plugin, and could create a custom callout for each highlighter colour, but I don’t know how to adjust the base code.
CSS Snippet
/* Yellow */
.literature-note .callout[data-callout-metadata="#ffd400"] { --callout-color: 255, 204, 0;
}
/* Red */
.literature-note .callout[data-callout-metadata=""#ff6666"] { --callout-color: 255, 59, 48;
}
/* Orange */
.literature-note .callout[data-callout-metadata="#f19837"] { --callout-color: 255, 149, 0;
}
/* Green */
.literature-note .callout[data-callout-metadata="#5fb236"] { --callout-color: 40, 205, 65;
}
/* Blue */
.literature-note .callout[data-callout-metadata="#2ea8e5"] { --callout-color: 0, 122, 255;
}
/* Magenta */
.literature-note .callout[data-callout-metadata="#e56eee"] { --callout-color: 255, 87, 255;
}
/* Purple */
.literature-note .callout[data-callout-metadata="#a28ae5"] { --callout-color: 125, 84, 222;
}
Here is the base code I’m using in the template for the annotations, currently.
set zoteroColors = {
"#2ea8e5": "blue",
"#5fb236": "green",
"#a28ae5": "purple",
"#ff6666": "red",
"#ffd400": "yellow",
"#f19837": "orange",
"#aaaaaa": "grey",
"#e56eee": "magenta"
}
-%}
{%-
set colorHeading = {
"blue": "Central Points",
"green": "Green",
"purple": "Purple",
"red": "Counter / Conflicts",
"yellow": "General Annotations",
"orange": "Direct Quotes",
"grey": "Grey",
"magenta": "Further Reading"
}
-%}
{%- macro calloutHeader(type) -%}
{%- switch type -%}
{%- case "highlight" -%}
Highlight
{%- case "image" -%}
Image
{%- default -%}
Note
{%- endswitch -%}
{%- endmacro %}
{%- set newAnnot = [] -%}
{%- set newAnnotations = [] -%}
{%- set annotations = annotations | filterby("date", "dateafter", lastImportDate) %}
{%- for annot in annotations -%}
{%- if annot.color in zoteroColors -%}
{%- set customColor = zoteroColors[annot.color] -%}
{%- elif annot.colorCategory|lower in colorHeading -%}
{%- set customColor = annot.colorCategory|lower -%}
{%- else -%}
{%- set customColor = "other" -%}
{%- endif -%}
{%- set newAnnotations = (newAnnotations.push({"annotation": annot, "customColor": customColor}), newAnnotations) -%}
{%- endfor -%}
{%- for color, heading in colorHeading -%}
{%- for entry in newAnnotations | filterby ("customColor", "startswith", color) -%}
{%- set annot = entry.annotation -%}
{%- if entry and loop.first %}
###### {{colorHeading[color]}}
{%- endif %}
> [!quote]+ {{calloutHeader(annot.type)}} ([Page {{annot.page}}]({{annot.desktopURI}}))
{%- if annot.annotatedText %}
> {{annot.annotatedText}} {% if annot.hashTags %}{{annot.hashTags}}{% endif -%}
{%- endif %}
{%- if annot.imageRelativePath %}
> ![[{{annot.imageRelativePath}}]]
{%- endif %}
{%- if annot.ocrText %}
> {{annot.ocrText}}
{%- endif %}
{%- if annot.comment %}
> - **{{annot.comment}}**
{%- endif -%}
{%- endfor -%}
{%- endfor -%}