Adding a Header Note section to reuse Javascript

I use Javascript in my notes to add functionality like formatting card tags, slightly modifying a card’s contents, etc. When a note has more than one card type and I want to reuse javascript functionality, I need to copy-paste code but that is very error-prone. It would also make it easier to maintain my notes if I can put all the javascript in one place and it’s separate from HTML, like I do now with CSS (Styling).

Would it be possible to add a “Shared Header Template” section to the Card Types editor whose contents would be wrapped around tags and rendered before the Front Template of a card at render time, a bit like how the Styling section works?

One thing you can do now is putting JavaScript in a separate file in your media folder, then referencing it like this:

<script src="_file.js"></script>

You then only have to duplicate this line in other templates.
Note that the filename should start with an underscore.

2 Likes

You could try using Asset Manager, which basically does what you want: every note type is given an asset collection, and for each asset (might it be JS, HTML, or whatever) you can choose where and how to insert it into a card template.

1 Like