How to get currentTiddler from javascript?

80 views
Skip to first unread message

Conner Phillips

unread,
May 29, 2017, 2:38:14 PM5/29/17
to TiddlyWikiDev
I made this post in the main group, per request moving it here.

Original:
"""
I'm guessing this is through the $tw.wiki interface somehow?

Thanks!
"""

FrD's response:
"""
Hi,

From inside a widget or a macro, just call :
this.getVariable("
currentTiddler");

This method is defined in

$:/core/modules/widgets/widget.js

Have a look at this file.

Regards

FrD
"""

Conner Phillips

unread,
May 29, 2017, 2:41:11 PM5/29/17
to TiddlyWikiDev
Sorry, I should have added more detail. My hope is to access it from within plugins/tiddlywiki/filesystem/filesystemadaptor.js, part of the node.js server.

In that file itself there seems to be a reference with

content = self.wiki.renderTiddler("text/plain","$:/core/templates/tiddler-metadata",{variables:
 
{currentTiddler: tiddler.fields.title}});

But I don't get what is going on there and if I can use it.

PMario

unread,
May 29, 2017, 3:11:50 PM5/29/17
to TiddlyWikiDev
Hi Connor,

If you are inside the  FileSystemAdaptor.prototype.saveTiddler = function(tiddler,callback)  function you can use the tiddler variable. Which is always the current tiddler, since the save function is called  with it as the parameter.

if you do a console.log("tiddler: ", tiddler) inside the function and restart the server, you'll see, what's going on and how the tiddler object looks like.

hope that helps. ... If it doesn't, you need to explain in more detail, what you want to achieve. ... It's about the git add, git commit handling I guess?

-mario

Conner Phillips

unread,
May 29, 2017, 4:05:53 PM5/29/17
to tiddly...@googlegroups.com
Hi PMario,

Sorry for the confusion but I confused myself. I haven't quite recovered from an overly fun weekend... The way I want to use this is for creating a history tab, and not related to saving at all! FrD did have the correct answer I was looking for. Minimum working example for posterity:

Don't forget to reload the page or restart the node.js server for this to take effect.

(is there any way to mark a post as solved?)

filename=test.js:
/*\ title: test.js
type: application/javascript
module-type: macro <<test>> \*/

(
function(){
/*jslint node: true, browser: true */
 
/*global $tw: false */
"use strict";

exports
.name = "test";

exports
.params = [];

/* Run the macro */

exports
.run = function() {
 
return this.getVariable("currentTiddler");
};
})();

Reply all
Reply to author
Forward
0 new messages