TW5: dynamically generate input tables?

444 views
Skip to first unread message

Dave

unread,
Oct 25, 2015, 11:44:12 PM10/25/15
to TiddlyWiki
In TWC you could create a dynamically generated table using ForEachTiddlerPlugin, something like this:

<<forEachTiddler
 where
 'tiddler.tags.contains("ClinicalDiagnoses")'
 sortBy
 'store.getValue(tiddler,"wt")'
 descending
 write
        '(index < 5) ? "| [["+tiddler.title+"]] |  ("+store.getValue(tiddler,"wt")+") | +++^*@[>]...<<tiddler "+tiddler.title+"\>\>===|\n" : ""'
>>


Is there a relatively simple equivalent in the current TW5?  I see something like it in this thread about editable tables:

https://groups.google.com/forum/#!searchin/tiddlywiki/editable$20tables/tiddlywiki/XeCYubR8YrU/J_buhitP9zsJ

, but I was wondering if there's a simpler way (I look at that code and don't really understand it yet) to do the same thing?




The use case is this:  I'm trying to learn TW5 by making a TW for assisting in swim coaching.  I have a group of tiddlers (names of swimmers) tagged "swimmers", and I want to be able to generate a tiddler with a table of names and editable times based on something like this:

| <$list filter="[tag[swimmers]sort[title]]"/> | <$edit-text tiddler="50mFreestyle" field="time"/> |

but of course this will make only one row with all the names in the first cell and a single edit box for the one field



here's another idea I had that doesn't work:

macro:
\define race(name:"name" time:"0:00")
| $name$ | <$edit-text tiddler="50mFreestyle-$name$" field="time"/> |
\end

tiddler that calls the race macro:
<<race name:"<$list filter="[tag[swimmers]sort[title]]"/>">>



Ideally maybe there's a way to dynamically create a DataTiddler in the DictionaryTiddler format... I'm okay with having the info attached to the swimmers tiddlers but it would probably be better to end up with DataTiddlers for each "race"


Any suggestions?

Mark S.

unread,
Oct 26, 2015, 12:54:30 AM10/26/15
to TiddlyWiki
This bit here:


| <$list filter="[tag[swimmers]sort[
title]]"/> | <$edit-text tiddler="50mFreestyle" field="time"/> |

needs to be rewritten something like:

<table>

<$list filter="[tag[swimmers]sort[title]]">
<tr><td><$view field="title"/></td><td><$edit-text field="50mFreestyleTime" /> </td></tr>
</$list>
</table>

... (untested) where I assume each swimmer's tiddler has a field "50mFreestyleTime" (You don't have to make the field in advance)

All your activity needs to happen inside of the <$list></$list> construct. You have to be sure to balance all the tags. I've never had much luck using the Pipes inside of <$list>, so I just use HTML table tags instead.


Dave

unread,
Oct 26, 2015, 1:14:20 AM10/26/15
to TiddlyWiki
Thank you Mark - that gets me headed in the right direction.  

:)

I was just looking at adapting the table structure from here:
http://tiddlywiki.com/#Filter%20Operators:[[Filter%20Operators]]

just before I checked the thread, but your example is way farther than I got doing that.

Dave

unread,
Oct 26, 2015, 1:19:01 AM10/26/15
to TiddlyWiki
Do you happen to know how to convert those tiddler titles into links?  Just adding [[ and ]] doesn't work.

Jed Carty

unread,
Oct 26, 2015, 4:27:45 AM10/26/15
to TiddlyWiki
To make the titles links you can put <$link> and </$link> around the title like this (using the example from mark):

<table>


<$list filter="[tag[swimmers]sort[title]]">
<tr><td><$link><$view field="title"/></$link></td><td><$edit-text field="50mFreestyleTime" /> </td></tr>
</$list>
</table>

Dave

unread,
Oct 26, 2015, 9:42:39 AM10/26/15
to TiddlyWiki
Awesome, thanks! (And it's so easy too!)

Dave

unread,
Oct 26, 2015, 5:27:52 PM10/26/15
to TiddlyWiki
I almost have the best case senario (a separate tiddler with appropriate data in fields):

\define race(event:"event")

<table>
<$list filter="[tag[swimmers]sort[title]]">
<tr><td><$link><$view field="title"/></$link></td><td><$edit-text tiddler='$event$' field='<$view field="title"/>' /></td></tr>
</$list>
</table>
\end

that macro works, e.g. <<race event:"50mFreestyle">> will construct the table, but I can't seem to get the swimmers names as the field name in the new tiddler [[50mFreestyle]]

the new tiddler in this case gets made with a field called "<$view field="title"/>"


I also tried with single and double curly brackets {{ }} and that didn't work either.

I suspect the problem is that since I specified the tiddler name just before it the following <$view field="title"/> is not the same as the previous <$view field="title"/> that wrote the swimmers name in the previous table cell to the left (or at least that may be part of the problem)

Do I have to set a variable somehow in the first cell to be able to use it in the adjacent cell?



I tried this (didn't work):

\define race(event:"event")

<table>
<$list filter="[tag[swimmers]sort[title]]">
<tr><td><$link><$view field="title"/></$link><$set name="swimmer" value=$title$></set></td><td><$edit-text tiddler='$event$' field=$(swimmer)$ /></td></tr>
</$list>
</table>
\end

and this didn’t work either:

\define race(event:"event")

<table>
<$list filter="[tag[swimmers]sort[title]]">
<tr><td><$link><$view field="title"/></$link></td><td><$edit-text tiddler='$event$' field="[tag[swimmers]sort[title]]"/></td></tr>
</$list>
</table>
\end


Any suggestions?

Jed Carty

unread,
Oct 26, 2015, 5:36:25 PM10/26/15
to TiddlyWiki
You use {{!!title}} in this case.

\define race(event:"event")

<table>

<$list filter="[tag[swimmers]sort[title]]">
<tr><td><$link><$view field="title"/></$link></td><
td><$edit-text tiddler='$event$' field={{!!title}}/>' /></td></tr>
</$list>
</table>
\end


You may be able to get some help looking at what I made here.

Jed Carty

unread,
Oct 26, 2015, 5:37:59 PM10/26/15
to TiddlyWiki
Sorry, there was some copy-paste trouble, this is what it should be:


\define race(event:"event")

<table>
<$list filter="[tag[swimmers]sort[title]]">
<tr><td><$link><$view field="title"/></$link></td><td><$edit-text tiddler='$event$' field={{!!title}}/></td></tr>
</$list>
</table>
\end

Dave

unread,
Oct 26, 2015, 6:06:18 PM10/26/15
to TiddlyWiki
That's It!!  Thank you! I'll be using that for a long time (and your other one from the above thread will come in handy too!)

:)

Dave

unread,
Oct 27, 2015, 8:33:02 PM10/27/15
to TiddlyWiki
Oops, spoke too soon.

Something weird is happening with this and I've posted the problem on the dev group:

https://groups.google.com/forum/#!topic/tiddlywikidev/ZGfZH_BVOO0

Dave

unread,
Oct 28, 2015, 11:15:15 AM10/28/15
to TiddlyWiki
nevermind - I did a stupid mistake:  was playing around with different versions of the same macro and left one there with the same macro name.  They were just interfering with one another.

Moral of the story, if something weird is happening with your macros, search for "define (macroname)" (rather than "<<(macroname)")

Reply all
Reply to author
Forward
0 new messages