Macro with substitution

89 views
Skip to first unread message

Tristan Kohl

unread,
Feb 8, 2018, 10:10:37 AM2/8/18
to TiddlyWiki
Hey guys,

for my wiki I need to substitute part of a filter which gets passed to a macro which in turn builds a table from those tiddlers.

My call looks like this:
<<table [tag[action]hive{!!title}] "title date text" "UID Date Notes">>
Obviously that does not work (I dropped a console.log in my JS macro), my macro gets passed the filter without substituted title. What else I tried and did not work:
  • Enclosing the filter in quotes
  • Using the filter without quotes
  • Using {{!!title}}
  • $set a variable and concatenate the filter: [tag[action]hive<var>] - Results in an TW error claiming the widget being null (maybe my macro is not bullet proof)
  • $set a variable by making the substitution the vars value: <$set name="var" value={{!!title}}>

My initial thought was this might be caused by the tiddler being transcluded via the tabs macro. But when I just drop the filter inside a list widget it shows the correct tiddlers and a {{!!title}} inside the transcluded tiddler revealed the name of the "parent" tiddler - so no problem there.


I am out of ideas so I came here hoping someone is willing to point me into the right direction.


Cheers,

Tristen

Mark S.

unread,
Feb 8, 2018, 10:32:15 AM2/8/18
to TiddlyWiki
Whenever you need to concatenate, you almost need a helper macro. Something like this might work:


\define myfilter() [tag[action]hive[$(title)$]]

<$vars title={{!!title}}>
<$macrocall $name=mymacro filter=<<myfilter>> columns="title date text" columns2="UID Date Notes"/>
</$vars>

Of course, I'm just guessing at your argument names and I had no way of testing this. You might be able to do this without using <$macrocall>, but macrocall is usually a little more predictable. You could also set up your environmental variables and then pick them up inside your JS macro using getVar (or is it getVariable? -- look around). Then you could concatenate within your JS (JS being a lot more predictable than TW syntax).

Good luck

-- Mark

Tristan Kohl

unread,
Feb 8, 2018, 10:44:45 AM2/8/18
to TiddlyWiki
Hi Mark,

that works, thank you so much for this I would never have come to this by myself.

However my guts hurt when I see a macro defined inside a tiddler. I know that this is the way TW works but whenever I develop software I work very hard to separate concerns as much as possible so mashing everything together is a tough pill :)

Nevertheless this solves my problem so thanks again.

Cheers,
Tristan

Mark S.

unread,
Feb 8, 2018, 11:04:35 AM2/8/18
to TiddlyWiki
You could define the macro globally in it's own tiddler, so it's separate from the rest of the code. Or, as I mentioned, you could do the concatenation inside your JS macro.

Have fun
-- Mark
Reply all
Reply to author
Forward
0 new messages