[TW5] Newbie can't call javascript macros

970 views
Skip to first unread message

Erock

unread,
Oct 17, 2016, 4:04:10 AM10/17/16
to tiddl...@googlegroups.com
I have been learning about javascript macros recently and was trying to create a simple one to start with, but I can't seem to get it to work. I've read lots of documentation, forums, etc., but still can't seem to figure out why it won't work. Here is what I've been doing. I set up two tiddlers, JsTiddler and RunTiddler. I added a very simple javascript macro to JsTiddler, and set its type = "application/javascript" and module-type = "macro". Here is the text:
/*\
title: JsTiddler
type: application/javascript
module-type: macro
\*/

(function(){

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

exports
.name = "jstiddler";

exports
.params = [];

/*
Run the macro
*/

exports
.run = function() {
   
return "Hello World";
};

})();

I then created a second tiddler to import and display the macro called RunTiddler. This is its text:
<$importvariables filter="[[JsTiddler]]">
<$macrocall $name="jstiddler" />
</$importvariables>

However, when I run this, all I get is a blank tiddler.  I have tried filtering in different ways (such as using tags), but that didn't help either. I have also been able to use <<now>> and <<version>> in both <<>> and <$macrocall> syntax, so I know that my wiki can use js tiddlers. Can anyone tell me what I'm doing wrong? Thanks.

Erock

unread,
Oct 17, 2016, 4:24:54 AM10/17/16
to tiddl...@googlegroups.com
Well, I actually managed to figure it out soon after posting this, but the reason for the fix was a little weird so I'll document it for others. It seems that for javascript changes the tiddler doesn't automatically refresh. Instead you need to either:
  • Close and reopen the page
  • Click the refresh button in tiddlywiki (you can add it in the tools menu)
After that the changes should show up.

Jed Carty

unread,
Oct 17, 2016, 4:54:40 AM10/17/16
to TiddlyWiki
Any javascript that you edit doesn't take effect until the entire page has been reloaded. This is an important security feature for any wiki hosted online.

Khalfani Wadlington

unread,
Dec 28, 2019, 6:29:02 PM12/28/19
to TiddlyWiki

Can we post that to the documentation.
I just ran into this same issue and didn't know that

David

unread,
Feb 27, 2020, 10:26:06 AM2/27/20
to TiddlyWiki
Thanks for putting together this simple script.  However, it did n't work for me.  I also get a blank tiddler. 

I have tried the refresh button as well as saving and reloading the whole page.

I created a new Tiddler called "JsTiddler" and put your content in it, and set the "Type" field to "application/javascript".  In the current version of TW, I do not see a field for "module".

Then i created a new tiddler like you did to test it.  I kept the type as the default (text/vnd.tiddlywiki) and pasted in your code.

I reloaded the tw and my test tiddler is still blank.

I'm not new to JavaScript, but have an intermediate knowledge of that.  But I'm new to TW, especially macros.

Joshua Fontany

unread,
Feb 28, 2020, 5:49:36 PM2/28/20
to TiddlyWiki
You have to manually add a "module-type" field and set it's value to "macro".

Here is a bare-bones example from the wiki-core (note the tiddler meta-data for this javacript macro is in a comment in the heading of the file):
https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/macros/version.js

Best,
Joshua Fontany

David

unread,
Mar 2, 2020, 8:19:22 AM3/2/20
to TiddlyWiki
Thank you Joshua!  That one worked!
Reply all
Reply to author
Forward
0 new messages