TW5: javascript macros

60 views
Skip to first unread message

rooster91an

unread,
Jul 3, 2019, 6:23:26 AM7/3/19
to TiddlyWiki
Hello everybody!

I'm stuck in a basic and probably easy thing: I cannot get any javascript macro to work in my tiddlywiki. My wiki is a 5.1.19 version running on nodejs. 

For an example let's take this makro from TW5 Magick (http://tw5magick.tiddlyspot.com/):

===========
/*\
title: $:/macros/skeeve/mysamplemacro.js
type: application/javascript
module-type: macro

<<mysamplemacro character address>>

Example:
<<mysamplemacro>>
<<mysamplemacro "Donald Duck">>
<<mysamplemacro "Mickey Mouse" "Mouse House">>

\*/
(function(){

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

/*
Information about this macro
This is the mysamplemacro of Tiddly Wiki 5 written in JavaScript 
*/

exports.name = "mysamplemacro";

exports.params = [
    { name: "character" },
    { name: "address" }
];

/*
Run the macro
*/
exports.run = function(character, address) {
    if( !character) character = "Bugs Bunny";
    if( !address) address = "Rabbit Hole Hill";
    var output ="Hi, I'm " + character + " and I live in " + address;
    return output;
};

})();
============

This is quite simple and it works perfect on TW5 Magicks Tiddlywiki. I imported this above tiddler to my wiki and the field definitions came with it: 'Type: application/javascript' and 'module-type: macro'. 

TW5 Magick, the source of this example, runs on an outdated 5.0.7-beta. To access the macro a simple <<mysamplemacro "Donald Duck">> does it there. 

On my 5.1.19: nope. 

At tiddlywiki.com I found the \define pragma for standard macros. I found https://tiddlywiki.com/dev/index.html#JavaScript%20Macros, which explains the basics of javascript macros. I was reading google groups for hours. But I didn't find out how to bring this together to a working solution in a current version of tiddlywiki.

Could someone please give me an example how to access this macro?

Thank you!

BurningTreeC

unread,
Jul 3, 2019, 6:31:09 AM7/3/19
to TiddlyWiki
Hi, I've tried your example and it works for me on a recent tiddlywiki

Maybe you just forgot to save and reload?

rooster91an

unread,
Jul 3, 2019, 7:13:31 AM7/3/19
to TiddlyWiki
Hi BurningTreeC

you are right. I had to restart my tiddlywiki nodejs server. Didn't know that.
Thanks a lot!

Oliver
Reply all
Reply to author
Forward
0 new messages