# Macro

25 views

### vinvi...@gmail.com

Feb 5, 2023, 10:24:48 AMFeb 5
to TiddlyWiki
Hi, I'm trying to make a macro.

This is my code so far:

\define checkbox-list()<$list variable="LIST-FROM-FIELD" filter="[list[!!LIST-FROM-FIELD]]"><br><$checkbox listField="WRITE TO FIELD" checked=<<LIST-FROM-FIELD>>> <<LIST-FROM-FIELD>></$checkbox></$list>

It now reads the values from a field and displays them with a checkbox in front of them.
By checking the checkbox, the corresponding value is written to another field.

I would prefer that when calling the macro I could determine which values should be displayed
without having to put them in a field.

Something like:
<<checkbox-list "values to list" "Name-field-to-write-to">>

I've been working on $myvar$. and enlist $mylist$.. I can't figure it out.

Is there anyone who can help me with this?

### Eric Shulman

Feb 5, 2023, 11:03:31 AMFeb 5
to TiddlyWiki
Give this a try:

\define checkbox-list(values,fieldname)
<$list filter="[enlist[$values$]]" variable="thisValue" > <div><$checkbox listField="$fieldname$" checked=<<thisValue>>> <<thisValue>></$checkbox></div> </$list>
\end

Notes:
* If the values list has items that contain double quotes or square brackets, those characters will interfere with the parsing of the $list filter syntax. To avoid this problem, instead of writing filter="[enlist[$values\$]]", you can write: filter="[enlist<__values__>]".  see https://tiddlywiki.com/#Macro%20Definitions%20in%20WikiText for more info.
* Note also that, while brackets (square, angled, or curly) within wikitext syntax are doubled, when used in filter syntax, they are SINGLE (i.e., [enlist<__values__>]... NOT [enlist<<__values__>>])

enjoy,
-e