How to resolve a (currentTiddler) variable when in use as a parameter for a js macro?

132 views
Skip to first unread message

NT

unread,
Dec 4, 2015, 5:48:49 PM12/4/15
to TiddlyWiki
What works:

1.

A "normal" macro

\define d1jpg(filename) 
[img[./path/$filename$.jpg]]
\end

called like this

<<d1jpg "$(currentTiddler)$">>

where "$(currentTiddler)$" is replaced by the title of the calling tiddler.

2.

A javascript macro 

/*\
title: $:/macros/mine/pathtype.js
type: application/javascript
module-type: macro
<<pathtype $filename$>>
Example:
<<pathtype "20150331_195734.mp4#t=0,17">>
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: true */
"use strict";
exports.name = "pathtype";
exports.params = [
  { name: "filename" }
];
/*
Run the macro
*/
exports.run = function(filename) {
return filename;
};
})();

called with a "normal" string as parameter like this

<<pathtype "20150331_195734.mp4#t=0,17">>

------

What's not working (or not working as expected / wanted):

A js macro like the above called with wikitext variable (currentTiddler) like

<<pathtype "$(currentTiddler)$">>

because the variable is not resolved to it's value, but it's name treated as string.

--> Question: What to change either in the call or in the js-macro so that the currentTiddler variable is resolved to the title of the tiddler within the js function?
Thanks for your patience, I am still struggling with the wiki syntax.
Kind regards.




BJ

unread,
Dec 4, 2015, 6:47:03 PM12/4/15
to TiddlyWiki
HI NT, try this:

 <$macrocall $name="pathtype" filename="<<currentTiddler>>"/>

all the best
BJ

NT

unread,
Dec 5, 2015, 6:44:25 AM12/5/15
to TiddlyWiki


Am Samstag, 5. Dezember 2015 00:47:03 UTC+1 schrieb BJ:
HI NT, try this:

 <$macrocall $name="pathtype" filename="<<currentTiddler>>"/>

all the best
BJ

Hey BJ, thanks for suggestions!

OK, this works partly, but I spotted a strange behavior.
If I just return the filename inside the js function your solution works fine and the currentTiddler variable is resolved to it's value.

But if I want to return something from the js function like 

"[img[" + path + filename + ".jpg" + "]]" 
(the variable concatenated inside a string)

the result is something like 

[img[./path/<<currentTiddler>>.jpg]]

so again the variable is not resolved.
Seems I have to change something inside the js function or the way I return it.
Can you tell me what or how to do it? 

Eric Shulman

unread,
Dec 5, 2015, 7:13:43 AM12/5/15
to TiddlyWiki
On Saturday, December 5, 2015 at 3:44:25 AM UTC-8, NT wrote:
Am Samstag, 5. Dezember 2015 00:47:03 UTC+1 schrieb BJ:
 <$macrocall $name="pathtype" filename="<<currentTiddler>>"/>

the result is something like 
[img[./path/<<currentTiddler>>.jpg]]
so again the variable is not resolved.
Seems I have to change something inside the js function or the way I return it.

The syntax for widget parameters support the following general use-cases:
   foo="literal string"
   foo=<<someVariable>>
   foo={{TiddlerName!!fieldname}}
   foo={{DataTiddlerName##index}}

In your example, you have quotes around "<<currentTiddler>>", which makes it a literal text string, rather than getting it's current value.  Remove the quotes around "<<currentTiddler>>" and it should work.

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:

NT

unread,
Dec 15, 2015, 4:43:18 PM12/15/15
to TiddlyWiki
Thank you Eric, this was the solution for me and your short summary was quite informative.
Reply all
Reply to author
Forward
0 new messages