TW5 Need help with macro and transclusion as parameter

170 views
Skip to first unread message

Ezequiel Malamud

unread,
Jun 7, 2015, 1:53:40 PM6/7/15
to tiddl...@googlegroups.com

Hi all, I'm new using TiddlyWiki and I'm having some trouble to get a macro working using a transclusion output as parameter. None of the following works:


<<myMacro myParam="{{myTiddlerA!!some-field}}{{myTiddlerB!!some-field}}">>

<<myMacro myParam={{myTiddlerA!!some-field}}{{myTiddlerB!!some-field}}>>

<<myMacro "{{myTiddlerA!!some-field}}{{myTiddlerB!!some-field}}">>

<<myMacro """{{myTiddlerA!!some-field}}{{myTiddlerB!!some-field}}""">>

<$macrocall $name=myMacro myParam="{{myTiddlerA!!some-field}}{{myTiddlerB!!some-field}}"/>


I'm expecting myMacro (Javascript) to get the concatenation of the fields some-field of tiddlers myTiddlerA and myTiddlerB as the parameter but so far I just get the string "{{myTiddlerA!!some-field}}{{myTiddlerB!!some-field}}" as the argument. Any help would be much appreciated.


This does work as expected:


<$macrocall $name=myMacro myParam={{myTiddlerA!!some-field}}/>


but this doesn't:


<$macrocall $name=myMacro myParam="{{myTiddlerA!!some-field}}"/>

Mark S.

unread,
Jun 7, 2015, 3:07:19 PM6/7/15
to tiddl...@googlegroups.com
What I've done, and it might not be the best approach, when I've needed to concatenate two transclusions (which is what you're doing) is to call a macro within a macro.

\define myMacro(cat1:"" cat2:"")
<$macrocall $name="helper" scat1=$cat1$ scat2=$cat2$ />
\end
\define helper(scat1:"" scat2:"")
$scat1$$scat2$
\end

My output is: <<myMacro {{Value1}} {{Value2}}>>

Mark

Ezequiel Malamud

unread,
Jun 7, 2015, 8:18:46 PM6/7/15
to tiddl...@googlegroups.com
Thanks for your quick reply, unfortunately I couldn't make it work or I didn't understand you. myMacro in the code you supplied only displays the concatenated transclusions {{Value1}} {{Value2}}, how can I use that as the argument of another macro? Also I get an undesired result if the tiddler to transclude has spaces in the name (title). I think the problem is that transclusions don't occur inside quotes before the call to the macro, is it the way it's supposed to work?

Mark S.

unread,
Jun 7, 2015, 9:02:23 PM6/7/15
to tiddl...@googlegroups.com
You know, I'm not sure if you can call a parameterized macro from within another macro. But you can call it from within a widget, and you can call a macro as a widget. I put strings around the transclusions. I made a little macro to test the calling called echo. And I simplified the code:

\define myMacro(cat1:"" cat2:"")
$cat1$$cat2$
\end

\define echo(rpt:"")
Hello? $rpt$
\end

Then I called myMacro from within the test macro like this:

<$macrocall $name="echo" rpt=<<myMacro "{{Value 1}}" "{{Value2}}">> />

Output:

Hello? this is value1this is value2

This worked with my test data, where one of the tiddlers has spaces in its name.

HTH
Mark

Ezequiel Malamud

unread,
Jun 7, 2015, 11:08:56 PM6/7/15
to tiddl...@googlegroups.com
First of all thanks for your help Mark, I was able use your code and it works exactly as it should, except ( I suspect ) when the macro is defined in Javascript as it is in my case. I made a MWE, exported it as JSON and attached it here. The problem with my naive approach is that if there are no quotes around the transclusions only one gets passed as the argument, but if they are surrounded by quotes then the argument is literally passed.

PlotData.json

Ezequiel Malamud

unread,
Jun 8, 2015, 8:45:34 AM6/8/15
to tiddl...@googlegroups.com
Ok, I found a workaround that solves my problem. I made the argument to be a list of tiddler titles and parsed them inside the PlotData function. Here is (finally) a MRWE (R stands for really). Thanks for your help Mark!
PlotData.json
Reply all
Reply to author
Forward
0 new messages