JS Calculations in Tiddlers

I’ve recently had a need to embed some reasonably complicated JavaScript calculations into a TW, along with a nice form to fill in parameters.

No problem, the form is in one tiddler and the JS in another. Now I have two tiddlers!

Then I wanted to “hide” the JS, or at least make it less obvious, so I added “$:/” to the title.

The problem now is that it is not obvious that the two tiddlers are a matched pair and should always be together.

Is there some way to embed JavaScript into a tiddler, or some way to associate the JS tiddler with the form tiddler so if the form tiddler is dragged to a new wiki, the JS goes with it?

I got excited when I read about CompoundTiddlers in the latest 5.3.4, but was ultimately disappointed.

It seems if I really want to keep the two together my only option is to make a plugin with the JS and a macro to generate the form, then require people to add the plugin, create a “host” tiddler for the form and call the macro in that to generate it.

Is there anything I’ve missed?

Would giving them both the same tag do the job?

I will usually make it a plugin, and install it. So I can manage it in plugins list.

I totally get what you’re asking about/searching for. I don’t think there is a way that will work as you would like.

However, I will mention I use @pmario’s Bundler plugin to create (what I call) “facilities”. For example, I have a set of utility JS macros and associated forms etc for managing images, notionally, an “Image Facility” which is a bundle I can save/export/import between wikis.

But really, for the example you mentioned, a plugin sounds like the way to go (under current capabilities).

To include JavaScript you need to do so via a tiddler that has a module-type, save and reload. Traditionally we do this via a plugin and you will be prompted to reload.

You can just have two tiddlers, one containing the JavaScript and one calling it. Place them in a single package. Such as a json file or bundle. Drop this on a wiki and it’s installed.

  • However you still must save and reload.

This is in part so JavaScript can not be installed and run without the owner of the wiki with save permissions.

  • This stops the injection of JavaScript into tiddlywiki by a bad actor.

I was not aware of that plugin. I will need to take some time to understand it, but it sounds like a solution.