Hi there,
I wanted to make a string replacement and found no other possibility as to do it with a javascript macro.
/*\
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.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;
};
})();
I just copied to my wiki and named it $:/macros/skeeve/mysamplemacro.js like it was before.
Then I tried to call it within a tiddler named jsTest:
<<mysamplemacro>>
<<mysamplemacro "Donald Duck">>
<<mysamplemacro "Mickey Mouse" "Mouse House">>
But this did not work, there was no output.
So what went wrong???
I have read this: http://tiddlywiki.com/dev/index.html#JavaScript%20Macros
I wondered where to find and to set the module type.
Is this just done by putting one line in the macro source code like "
module-type: macro"?
As there is the speaking of a module-type "field" I expected to find it at the bottom of a tiddler in "Edit"-Mode between the System fields like current-tiddler, library or plugin type.
Also it is not clear to me if I have to tag the js-macro with $:/tags/Macro as the normal wikitext macros.
Also the naming convention is not clear to me. I want this macro globally accessible, but not mixed up in between the system macros.
I would be happy about suggestions to why my js macro is not working as I found the documentation about that a bit limited.
Thank you very much!