Hi, I'm trying to do something that is a bit beyond me. I'm trying to create my first global macro. At least, I think this should be a macro.
Goal
I want to generate a table of values from a defined set of fields from a set of macros based on a filter (usually defined by a tag).
I would like to turn that into a global macro that takes 2 parameters:
- A filter that defines the set of tiddlers to get data from. This should default to all tiddlers that are tagged with the title of the tiddler that calls the macro.
- A list of field names from those tiddlers to provide the data. This should default to the contents of the list field of the tiddler that calls the macro.
I think the "tiddler that calls the macro" should be in <<currentTiddler>>, is that right?
What I am having problems with
I can't figure out how to properly set the defaults in the macro to do what I want. Specifically, in the code below, the default for the filter parameter of the macro call should not explicitly define "grid" as the tag, but should take it from the title of the current tiddler.
\define grid(filter:"[tag[grid]]", list:"[list[]]")
<table>
<caption>data from $filter$</caption>
<tr><$list filter=$list$ variable="columntitle"><th><<columntitle>></th></$list><th>//Link//</th></tr>
<$list filter=$filter$ variable="rowtiddler"><tr>
<td><$link to=<<rowtiddler>> ><<rowtiddler>></$link></td>
<$list filter=$list$ variable="cellfield"><td> <$transclude tiddler=<<rowtiddler>> field=<<cellfield>>/> </td></$list>
</tr>
</$list>
</table>
\end
Future plans
I'm planning to replace the caption with a third option to set the caption and probably make the default no caption at all.
Why I want this
I have found that I'm using Tiddlywiki for a lot of things that involve organizing data and being able to put a bunch of that data into tables is a handy way to view it all.
- Keep track of what I've got the PVR doing (it will record up to 2 shows at a time but doesn't have any way of telling me what is conflicting when there are conflicts. Thus a table of what is scheduled when sorted by time and day help find those.
- I like trolling the clearance bins for DVDs and bluerays. A few times I've re-bought something I already have. Now I can check my wiki from my phone before buying.
- I have a crazy number of projects to keep track of at work, this helps me categorize them. Plus, the time tracking system isn't the most reliable at times, tiddlywiki gives me a place to record things until the system comes back online.
- This started with Stephan Hradek's TW5 Magic example of a contacts database and I'm trying to add some features I would like.
- I'm trying to get to the point that I can create an add-in for tiddlywiki that generates a table instead of me constantly copy/pasting my table generating code every time I want to create a table.
Things I don't understand
Why I have to put html into the macro instead of using the wiki markup.
Why I can sometimes use shorthands like {{ ... }} and <<...>> but other times I have to use <$.../> and, more importantly how to identify when so I don't keep re-writing things because they don't work.