I you defined a custom widget in TiddlyWiki script, you can include one within another, keeping in mind widgets donāt typically return a value to the calling widget, but they can display a result or even an element like a button.
In tiddlywiki script you can even redefine an existing widget using the GenesisWidget
I do try to urge people to use the tiddlywiki way, not revert to JavaScript.
Especially in this example because it seems your outer widget is effectively what one can generate from a list widget.
Thanks @TW_Tones. I understand it is better to use wikitext way to develop a new widget.
But some operation I plan to do is very complicated for data processing. It would be really hard to achieve through wikitext. So I think it would be easier to develop with js.
@buggyj Thanks for your suggestions. After rethinking @TW_Tones comments, I think the following method would be easier and flexible to develop.
As my main target is to generate parameter values in widget1 using scripts, I could develop macros to return the generated values using wikitext for simple task and js for complex tasks, for example,
<$widget1 type="t1" data=<<get-data>> />
With this idea, I successfully developed a demo to display a map for my tw-htmlwidgets plugin as a starting point.
Another option may be a custom filter written in JavaScript. I came across a discussion and example of js filter here : https://groups.google.com/g/tiddlywiki/c/M6wADVDjyTE?pli=1 (More info in TiddlyWiki/Dev under āFilter Operatorsā)
You use your js filter within a filter expression in wikitext to generate the output you need.
Just for an addition, I found a method .makeChildWidget(parseTreeNode, options) that could create a child widget and set the caller widget as its parent.
In the context of a widget (like in the file of your customized JS widget), call the method like the way below:
// Create a div node as the widget container
let node = $tw.utils.domMaker("div");
// Create a child codeblock widget
let widget_code = this.makeChildWidget({
type: 'codeblock', // this should be added
attributes: {
code: '{"a": 1, "b": 2}',
language: 'json'
}
}, null);
// Render it
widget_code.render(node, null);