I’m struggling a little to get started with Javascript macros on TiddlyWiki… I’ve found this dev page https://tiddlywiki.com/dev/index.html#JavaScript%20Macros that tells that the functional examples are a good starting point… So I’ve tried to copy them for creating a new one as the following:
- I’ve copied all the content from the macro
$:/core/modules/macros/jsontiddlers.js
to a new tiddler called$:/core/modules/macros/testmacro.js
. - I’ve added the
Type
toapplication/javascript
on my$:/core/modules/macros/testmacro.js
Tiddler, just like the original file - I’ve added the
module-type
tomacro
on my$:/core/modules/macros/testmacro.js
Tiddler, just like the original file. - I’ve substituted the content of the Tiddler changing jsontiddlers to testmacro… So the new content is:
/*\
title: $:/core/modules/macros/testmacro.js
type: application/javascript
module-type: macro
Macro to output tiddlers matching a filter to JSON
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "testmacro";
exports.params = [
{name: "filter"},
{name: "spaces"}
];
/*
Run the macro
*/
exports.run = function(filter,spaces) {
return this.wiki.getTiddlersAsJson(filter,$tw.utils.parseInt(spaces));
};
})();
For testing if it was working, I tried to use this macro just like I use jsontiddlers
… So, the following macro returns to me in JSON all the tiddlers that start with D:
<$macrocall $name="jsontiddlers" filter=[prefix[D]] $output="text/raw"/>
And my new created macro doesn’t return anything:
<$macrocall $name="testmacro" filter=[prefix[D]] $output="text/raw"/>
I think I’m probably missing some steps… What am I missing in the process of creating a Javascript macro?