Replies: 1 comment
-
There's several different ways you could go about something like this. Some other easy alternatives:
And something that takes a little more setup but is my personal preference and what I'm currently doing:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was finding that I was rewriting code over and over (getNote, getContent, etc. etc. etc.). It was a pain to have to copy the code to new notes and, if there was an improvement, have to go to all those locations to make the change.
Additionally, I have some JSON charting code, where each chart's code is identical, except for a configuration object.
SO, tonight I started thinking about how to have some code reuse. And it worked!
Implementing Dynamic Includes:
In a Note where you want to use some code from somewhere else in your tree, create a new JS Frontend child note (e.g. myIncludesNote), paste the code below into the myIncludesNote and then add an attribute to the myIncludesNote called "#myIncludes" that has a value that is a comma delimited list of NoteIDs. The included note will run, since it is a child of your executing code, and will inject the #myIncludes notes' contents into the rendered document
Example Tree Structure:
SomeJSNote - ID: rqiajsfajdlfkbnla (anywhere in your Trilium Tree)
SomeJSNote2 - ID:safuehfalejsdf (anywhere in your Trilium Tree)
.
.
.
Render Note "Display"
Steps:
#myIncludes=Aa3YQRk8rVe5,y0uciphMeWc5,MgcHFCsoVc4Y
Now, anytime you load the render note, both SomeJSNote and SomeJSNote2 will be added to the output and executed.
I have attached an exported tree demonstrating this...
myIncludes Example.zip
Hope this helps someone! I am using it a ton!
Beta Was this translation helpful? Give feedback.
All reactions