Getting a tiddler's fields from a widget plugin (JS)?

46 views
Skip to first unread message

stefano franchi

unread,
Mar 3, 2019, 7:37:56 PM3/3/19
to TiddlyWikiDev
I am sure this is stupid question whose answer is staring at me, but I can't find it:

How do you access a tiddler from within a widget plugin's code?

All I was able to find is that
1. All tiddlers are accessible by title from $tw.wiki
2. The title of a tiddle is stored in the widget's parent's transcludeTitle 

So, when I need the value of myField I end up with this expression in the plugin code:

myFieldValue = $tw.wiki(this.parentWidget.transcludeTitle).fields["myField"]

which looks to me as going from New York to Boston via Tokyo. Besides, I dislike using globals and would rather have the widget telling me the tiddler data it is working on.

Surely there's a better way?

Cheers,

Stefano

--
__________________________________________________
Stefano Franchi

stefano...@gmail.com
http://stefano.cleinias.org

BJ

unread,
Mar 5, 2019, 7:22:42 PM3/5/19
to TiddlyWikiDev
it can be obtained from the transclusion variable:

mywidget.getTidName = function() {
	var transclusion = this.getVariable("transclusion");	
	if (transclusion) {
		return transclusion.split('|')[1];
	}
	else {
		return "";
	}
}
Reply all
Reply to author
Forward
0 new messages