Call "other" plugin function from macro

13 views
Skip to first unread message

todd.c...@gmail.com

unread,
Nov 3, 2008, 12:39:31 PM11/3/08
to TiddlyWiki
Hi all,

I'd like to extend the <<list>> macro to display the icons that are
associated with tiddler. The macro <<tiddlerIcons>> is provided by
the TiddlerIconsPlugin. I believe the correct place to add this code
is:

config.macros.list.handler = function(place,macroName,params)
{
var type = params[0] ? params[0] : "all";
var list = document.createElement("ul");
place.appendChild(list);
if(this[type].prompt)
createTiddlyElement(list,"li",null,"listTitle",this[type].prompt);
var results;
if(this[type].handler)
results = this[type].handler(params);
for(var t = 0; t < results.length; t++) {
var li = document.createElement("li");
list.appendChild(li);
createTiddlyLink(li,typeof results[t] == "string" ? results[t] :
results[t].title,true);

// ***** START MY CODE *****
if(typeof results[t] == "string") {
tiddlerIcons("=" + results[t]);
}
// ***** END MY CODE *****
}
};

this causes the error: Error while executing macro <<list>>:
TypeError: tiddlerIcons is not a function

How do I call a plugin function from another macro?

Thanks,

Todd

Eric Shulman

unread,
Nov 3, 2008, 1:29:51 PM11/3/08
to TiddlyWiki
> How do I call a plugin function from another macro?

Try this:

if (config.macros.tiddlerIcons)

config.macros.tiddlerIcons.handler(place,"tiddlerIcons","="+results[t]);

Note use of conditional to ensure that the function is NOT called if
it is not defined, e.g., if TiddlerIconsPlugin isn't installed (or has
been disabled via the 'systemConfigDisable' tag).

enjoy,
-e

todd.c...@gmail.com

unread,
Nov 4, 2008, 12:28:41 PM11/4/08
to TiddlyWiki
Thanks!

One change:

config.macros.tiddlerIcons.handler(place,"tiddlerIcons",
["="+results[t]]);

since params is an array.

Todd

Eric Shulman

unread,
Nov 4, 2008, 1:42:04 PM11/4/08
to TiddlyWiki
> One change:
>      config.macros.tiddlerIcons.handler(place,"tiddlerIcons",
> ["="+results[t]]);
> since params is an array.

oops! :-)

-e

todd.c...@gmail.com

unread,
Nov 4, 2008, 3:25:16 PM11/4/08
to TiddlyWiki
I found two more hints:

In the list handler function, use "li" as the place to put the icons
after the tidder title:

config.macros.tiddlerIcons.handler(li,"tiddlerIcons",
["="+results[t]]);


In the tiddlerIcon handler function, add a space to the front of the
first icon:

if (this.map[tags[t]]) imgs.push(img.format(this.map[tags[t]]));
wikify(&quot;&amp;nbsp;&quot; +
imgs.join(&quot;&amp;nbsp;&quot;),place);

Eric Shulman

unread,
Nov 4, 2008, 3:34:51 PM11/4/08
to TiddlyWiki
> In the list handler function, use "li" as the place to put the icons
> after the tidder title:
> config.macros.tiddlerIcons.handler(li,"tiddlerIcons",
> ["="+results[t]]);
> In the tiddlerIcon handler function, add a space to the front of the
> first icon:

Instead of changing the handler, you can just use wikify() to directly
render a leading space into the 'li' element, prior to invoking the
handler, like this:

wikify("&nbsp;",li);
config.macros.tiddlerIcons.handler(li,"tiddlerIcons",
["="+results[t]]);

-e
Reply all
Reply to author
Forward
0 new messages