Macro with variable number of attributes (parameter)

69 views
Skip to first unread message

Mohammad

unread,
Nov 20, 2018, 11:36:39 PM11/20/18
to TiddlyWiki
The TW macro can accept the optional parameter! An optional parameter is the one you can send its value on macro call or you can ignore and macro will use some default value!
My question is can we have a macro with variable number of parameters (attributes)

See below macro

\define mypic(caption:"no caption", img)
<figure>
[img[$img$]]
<figcaption style="text-align:center;font-weight:700;">$caption$</figcaption>
</figure>
\end

I want to call mypic as below

<<mypic caption img>>

and

<<mypic caption img1 img2 img3>>



What do you think?


I know JS has this capability, see below


Mohammad

Mark S.

unread,
Nov 21, 2018, 12:19:09 AM11/21/18
to TiddlyWiki
You could pass a list in quotes, like:

\define stuff(myvar mylist)
I saw $myvar$
. Then <br/>
<$list filter="[enlist[$mylist$]]">
<$view field="title"/><br/>
</$list>
\end

-- Mark

TonyM

unread,
Nov 21, 2018, 1:42:36 AM11/21/18
to TiddlyWiki
Marks Idea of passing a list is a great one, and more elegant than this suggestion

However if there is a theoretical maximum you can just define it with img1 img2... img10 and include the logic to process only the ones provided (have a value).

Regards
Tony

Mohammad

unread,
Nov 21, 2018, 8:49:43 AM11/21/18
to TiddlyWiki
Hello Mark,
 your solution is amazing! thank you!

Cheers
Mohammad

Mohammad

unread,
Nov 21, 2018, 9:01:38 AM11/21/18
to TiddlyWiki
Hi Tony!
Thank you! I use the solution proposed by Mark, as I need to use them in css!

Mohammad
Reply all
Reply to author
Forward
0 new messages