TW5 stuck setting default for a macro

118 views
Skip to first unread message

Lost Admin

unread,
Mar 9, 2017, 11:29:40 AM3/9/17
to TiddlyWiki
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've created an example that almost works at http://thelostadmin.tiddlyspot.com/#grid

I would like to turn that into a global macro that takes 2 parameters:
  1. 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.
  2. 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.

Jed Carty

unread,
Mar 9, 2017, 11:38:55 AM3/9/17
to TiddlyWiki
The table macros I made made be useful to you: http://ooktech.com/jed/ExampleWikis/DynamicTables/



I am in the process of updating and moving my plugins to my new plugin library, so these should get an update at some point in the not too distant future.

Mark S.

unread,
Mar 9, 2017, 12:31:57 PM3/9/17
to TiddlyWiki


On Thursday, March 9, 2017 at 8:29:40 AM UTC-8, Lost Admin wrote:
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[]]")

Try "[tag<currentTiddler>]" . Might work in some cases.

 
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.

Study the documentation at tiddlywiki.com, especially the parts about filters and filter operators. The whole macro/transclusion/variables/parametres thing is inconsistent. It's not like a real programming language. I've gotten to the point where about 80% of the time I can figure out how to do what I want, but still end up banging head against the table too much of the time, and would be hard pressed to explain the parts that I do understand.

Use someone else's stuff (like Jed and Stephan) if you can.

Good luck!
Mark
 

Lost Admin

unread,
Mar 9, 2017, 1:23:43 PM3/9/17
to TiddlyWiki
Thanks. Your macros are way beyond my current ability but you did get me further along.

I've got the macro working with parameters and using a default (and changable) list of fields for the data and I can define a filter in the macro call but I still can't figure out how to set a default filter when none is passed in.

Current code:
\define grid(datafilter:"[tag[<<currentTiddler>>]]", list:"[list[]]")
<table>
   <caption>data from $datafilter$</caption>
   <tr><th>//Link//</th><$list filter=$list$ variable="columntitle"><th><<columntitle>></th></$list></tr>
   <$list filter=$datafilter$ 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

Calling it without arguments doesn't work:
<<grid>>

Calling with just a filter argument does work:

<<grid [tag[mygrid]]>>

<<grid [tag[mygrid]] [list[!!shortlist]]>>

So how do I set the default for the filter to be all tiddlers tagged with the title of the current tiddler (which is what I tried to do in the code)?

Jed Carty

unread,
Mar 9, 2017, 1:52:12 PM3/9/17
to TiddlyWiki
To make it do what you want by default use this:

\define grid(datafilter:"[tag<currentTiddler>]", list:"[list[]]")

Tobias wrote up a summary of a conversation that a few of us had on this group a while ago that may be useful to you. It is here http://tobibeer.github.io/tb5/#Variables%20vs.%20Parameters

Lost Admin

unread,
Mar 9, 2017, 2:00:24 PM3/9/17
to TiddlyWiki
I've got it working thanks to Jed's DynamicTables. Mine is far simpler (and far far less functional).

Enter code here...\define grid(myfilter, list:"[list[]]")
<$set name='datafilter' filter='$myfilter$' emptyValue=[tag[$(currentTiddler)$]]>
<table>
   <caption>data from <<datafilter>></caption>
   <tr><th>//Link//</th><$list filter=$list$ variable="columntitle"><th><<columntitle>></th></$list></tr>
   <$list filter=<<datafilter>> 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>
</$set>
\end


I don't understand why I have to set a variable for the filter in order to get it to work. How do I put the default value into the macro definition?



On Thursday, March 9, 2017 at 11:38:55 AM UTC-5, Jed Carty wrote:

Lost Admin

unread,
Mar 9, 2017, 2:34:49 PM3/9/17
to TiddlyWiki
Sorry but that doesn't seam to make a usable default.

Jed Carty

unread,
Mar 9, 2017, 2:50:46 PM3/9/17
to TiddlyWiki
Oh, sorry. It needs to be like this:

\define grid(myfilter:"[tag{!!title}]" list:"[list[]]")
<table>
   <caption>data from $myfilter$</caption>
   <tr><th>//Link//</th><$list filter="""$list$""" variable="columntitle"><th><<columntitle>></th></$list></tr>
   <$list filter="""$myfilter$""" 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

I forgot that the parsing rules for the defaults in macros don't do what I keep expecting the currentTiddler to do. The caption isn't what you expect this way though.

Eric Shulman

unread,
Mar 9, 2017, 2:58:01 PM3/9/17
to TiddlyWiki
I don't understand why I have to set a variable for the filter in order to get it to work. How do I put the default value into the macro definition?

The syntax you used for the datafilter parameter default value in your first code example is not correct.  You wrote:
\define grid(datafilter:"[tag[<<currentTiddler>>]]", list:"[list[]]")

However, the correct syntax for using a variable within the filter should be:
[tag<currentTiddler>]

The outer square brackets delimit the tag filter expression
The inner delimiters depend on the type of parameter being supplied to the tag filter
* [tag[sometag]]
   is for *literal* tag parameter values
* [tag<somevar>]
   uses the value stored in a variable as the tag parameter
* [tag{sometiddler!!somefield}]
   uses the value stored in a tiddler field. (note: you can omit the "sometiddler" portion of the tag parameter to refer to a field in the current tiddler OR omit the "!!somefield" portion to refer to the "text" field by default)

Hope that helps...

enjoy,
-e

Eric Shulman
TiddlyTools: Small Tools for Big Ideas (tm)
InsideTiddlyWiki: The Missing Manuals




Lost Admin

unread,
Mar 9, 2017, 3:24:06 PM3/9/17
to tiddl...@googlegroups.com
AH! that did it. Thank you Jed.

I don't see any way to mark this thread as complete, but you all helped me get my simple macro working.

It is publicly available at http://thelostadmin.tiddlyspot.com/#grid until I decide to rename it or cleanup the site.

Lost Admin

unread,
Mar 9, 2017, 3:30:36 PM3/9/17
to TiddlyWiki
Thank you. That helps me understand. I'm not sure how long I'll remember it, but I think I understand the differences.
Reply all
Reply to author
Forward
0 new messages