Discussion:
[tw] TW5 stuck setting default for a macro
2017-03-09 16:29:40 UTC
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

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.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.
Jed Carty
2017-03-09 16:38:55 UTC
The table macros I made made be useful to
you: http://ooktech.com/jed/ExampleWikis/DynamicTables/

Also I made a library tracker for the same reason
here: http://inmysocks.tiddlyspot.com/#%24%3A%2Fplugins%2Finmysocks%2FLibraryTracker%2FLibrary%20Tracker

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.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/b5246d27-8196-450c-85b6-47af7de52287%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
2017-03-09 18:23:43 UTC
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)? Post by Jed Carty http://ooktech.com/jed/ExampleWikis/DynamicTables/ http://inmysocks.tiddlyspot.com/#%24%3A%2Fplugins%2Finmysocks%2FLibraryTracker%2FLibrary%20Tracker 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. -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com. To post to this group, send email to ***@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/48b9e0ff-0404-443c-a2e7-7f720846bc46%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. Lost Admin 2017-03-09 19:00:24 UTC Permalink 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?
Post by Jed Carty
http://ooktech.com/jed/ExampleWikis/DynamicTables/
http://inmysocks.tiddlyspot.com/#%24%3A%2Fplugins%2Finmysocks%2FLibraryTracker%2FLibrary%20Tracker
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.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/1d33a758-f03e-4463-8bd0-12e37a912f11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eric Shulman
2017-03-09 19:58:01 UTC
Post by Lost Admin
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
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2a87ed9b-57c2-4871-a8ba-deff7fb1ec11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
2017-03-09 20:30:36 UTC
Thank you. That helps me understand. I'm not sure how long I'll remember
it, but I think I understand the differences.
Post by Lost Admin
I don't understand why I have to set a variable for the filter in order to
Post by Lost Admin
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
\define grid(datafilter:"[tag[<<currentTiddler>>]]", list:"[list[]]")
However, the correct syntax for using a variable within the filter should
[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
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/70b613be-f20f-45be-a555-f5de4b67717f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Mark S.' via TiddlyWiki
2017-03-09 17:31:57 UTC
Post by Lost Admin
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.
Post by Lost Admin
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 -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com. To post to this group, send email to ***@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/325bde1f-98ba-460e-83d9-88817f44236b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. Jed Carty 2017-03-09 18:52:12 UTC Permalink 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 -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com. To post to this group, send email to ***@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e7ead2d2-4768-4a42-afa7-65101d70806b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. Lost Admin 2017-03-09 19:34:47 UTC Permalink Sorry but that doesn't seam to make a usable default. Post by Jed Carty \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 -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com. To post to this group, send email to ***@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/c20b38d5-3b3a-4b17-bb45-519152cb7f1c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. Jed Carty 2017-03-09 19:50:46 UTC Permalink 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.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/95f5f863-21ed-4a91-a659-e5a5a9653188%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
2017-03-09 20:24:06 UTC
AH! that did it. Thank you Jed.
Post by Jed Carty
\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.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/8f85d643-b1fb-48ae-9bd6-1271df33667f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive: