[TW5] Easy way to display all values in a data tiddler? Macro to create a table based on a list of data tiddlers?

1,575 views
Skip to first unread message

Matthew Petty

unread,
Mar 27, 2016, 7:30:49 AM3/27/16
to TiddlyWiki
I am exploring the use of data dictionary tiddlers, and they seem to be very useful as a way of having data stored in the text of a tiddler, rather than in a field or tag.

Here's my thought process -
  • I work on multiple projects in my company, each with a job number, WBS code etc. I have a tiddler with a list of these codes.
  • I turned it into a table in the tiddler, before realising it would be better to have each project code in a separate tiddler.
  • First I had each tiddler contain the syntax for a table row: "| A | B | C |". But this didn't work when I used a list to return them.
  • I could have put the HTML tags in, but then I remembered data tiddlers.
  • OK, now I have a data tiddler for each project, with the following values:
jn_company:[[THIS]]
jn_project
:[[THAT]]
jn_number
:648021
jn_WBS
:10003
jn_cc
:0089
jn_ct
:07
jn_task
:000
jn_fnct
:00
  • By the way, it's nice that a value can be a wiki link.
  • So now I can do a list of all the data tiddlers called "Job Number: xxx", using the following syntax:


<$list filter="[prefix[Job Number:]]">

*{{##jn_company}}
*{{##jn_project}}
*{{##jn_number}}
*{{##jn_WBS}}
*{{##jn_cc}}
*{{##jn_ct}}
*{{##jn_task}}
*{{##jn_fnct}}
</$list>
  • But typing out all the text references got a bit tedious.
  • So the question is, is there a way to go through all the text references in order and return their values? Then I could do a macro which would return a row of a table, without having to specify the text references.


Sorry for the long post, but I wanted to give some background. Feel free to point out errors in the above.


Thanks,

Matthew


Hegart Dmishiv

unread,
Mar 27, 2016, 11:59:32 AM3/27/16
to tiddl...@googlegroups.com, mye...@sunyit.edu
Hi Matthew,

It's interesting you should mention this now, as I'm just about to start using data tiddlers in a quite different way. Maybe it might have some application for you. Maybe you (or someone else here) will point out a flaw in my idea that will cause me to have to rethink my solution. Either way, it's serendipitous.

I'm intending to create a data:value1, value2, ... valuex structure within a dictionary tiddler, rather than sticking to the expected data:value pair. I'll then use a custom macro to extract just the particular value from the string that is returned from the properly formed data:value pair.

For example, if I have the following data in my foobar dictionary tiddler :

foo: red,square,37
bar
: blue,circle,12
baz
: green,triangle,29

...I should be able to do a normal request of {{foobar##baz}} which will return the string "green,triangle,29". I can then chop that string up in a macro, using text manipulation tools to find the first, second, and third element, using a macrocall something like...

<$macrocall $name="decombobulate" foobarstring={{foobar##baz}} returnvalue="2" />

...which should return just the string "triangle". At least, that's the theory of it. I haven't tried it out for real yet. I'm intending to do this for the TiddlyCRM project I'm working on for the {{DesignWrite}} course semester project. I don't know if that will be useful for you as well, Matthew, but I'll put it out there anyway. All feedback gratefully accepted.

Hegart.

Eric Shulman

unread,
Mar 27, 2016, 3:12:30 PM3/27/16
to TiddlyWiki
On Sunday, March 27, 2016 at 4:30:49 AM UTC-7, Matthew Petty wrote:
I am exploring the use of data dictionary tiddlers, and they seem to be very useful as a way of having data stored in the text of a tiddler, rather than in a field or tag.
  • So the question is, is there a way to go through all the text references in order and return their values? Then I could do a macro which would return a row of a table, without having to specify the text references.

You can use the indexes[] filter to get the names of the items in a data tiddler:

Something like this:

<ul>

   <$list filter="[prefix[Job Number:]]">
      <$list filter="[<currentTiddler>indexes[]]" variable="thisIndex">
         
<li><$view index=<<thisIndex>>/></li>
      </$list>
   </$list>
</ul>


Note the use of variable="thisIndex"... this allows the inner $list to loop through the items without changing the value of "currentTiddler" that was set by the outer $list.


enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
InsideTiddlyWiki: The Missing Manuals


Matthew Petty

unread,
Mar 28, 2016, 6:17:51 AM3/28/16
to TiddlyWiki
Eric,
That's great, thank you. Now I can have:
<table>

<$list filter="[prefix[Job Number:]]">
<tr><td>{{!!title}}</td><$list filter="[<currentTiddler>indexes[]]" variable="thisIndex">
<td><$view index=<<thisIndex>>/></td>
</$list>
</tr></$list>
</table>
Which returns a nice table.

There are still a couple of issues.
First, if the text reference contains a wiki link, like "[[Link]]", then it is not returned as a link, but just as text with the square brackets. It would be nice to be able to have that as a link if it wants to be, and to ignore it if not.
Secondly, how can I set the order of the index list? It seems to be random at the moment. I'd like it to be in the order of the data in the tiddler, or failing that, alphabetical.
Thirdly, is it possible to return the names of the values, and not the values themselves? If that were possible, the a macro could be made which would do something like this:

<<data-tiddler-table "[prefix[Job Number:]]">>

would give a table with the first row:

| data value 1 name | data value 2 name | data value 3 name | data value 4 name |

and then one row per returned tiddler with the form:

| data value 1 | data value 2 | data value 3 | data value 4 |

That would be very generally  useful!

Eric Shulman

unread,
Mar 28, 2016, 10:12:57 AM3/28/16
to tiddl...@googlegroups.com
On Monday, March 28, 2016 at 3:17:51 AM UTC-7, Matthew Petty wrote:
Eric,
That's great, thank you. Now I can have:
<table>
<$list filter="[prefix[Job Number:]]">
<tr><td>{{!!title}}</td><$list filter="[<currentTiddler>indexes[]]" variable="thisIndex">
<td><$view index=<<thisIndex>>/></td>
</$list>
</tr></$list>
</table>
Which returns a nice table.

There are still a couple of issues.
First, if the text reference contains a wiki link, like "[[Link]]", then it is not returned as a link, but just as text with the square brackets. It would be nice to be able to have that as a link if it wants to be, and to ignore it if not.

Instead of the <$view> widget, use
<$transclude index=<<thisIndex>>/>

This will cause the value to be "translated" before it is "included" in the output (thus, "trans"+"clude"), so that any wiki syntax contained in the value will be processed (e.g., [[foo]] will become a proper link to a tiddler named "foo")
 
Secondly, how can I set the order of the index list? It seems to be random at the moment. I'd like it to be in the order of the data in the tiddler, or failing that, alphabetical.

As noted in the documentation for http://tiddlywiki.com/#indexes%20Operator, the names are returned "in no particular order".  However, as with any filter result, you can apply a [sort[]] operator to change the order:
<currentTiddler>indexes[]sort[]

Thirdly, is it possible to return the names of the values, and not the values themselves? If that were possible, the a macro could be made which would do something like this:

The indexes[] operator IS already returning the names... not the values.  The actual values are retrieved by the <$view> (or <$transclude>) widget.   Assuming that all the "Job Number" tiddlers have the same index names, you can write your table like this:

<table>
<$list filter="[prefix[Job Number:]limit[1]]">
<tr>
   
<td> <!-- EMPTY CORNER --> </td>
   <$list filter="[
<currentTiddler>indexes[]]" variable="thisIndex">
     
<td><<thisIndex>></td>
   </$list>
</tr>
</$list>

<$list filter="[prefix[Job Number:]]">
<tr>
   
<td>{{!!title}}</td>
   <$list filter="[
<currentTiddler>indexes[]]" variable="thisIndex">
     
<td><$view index=<<thisIndex>>/></td>
   </$list>
</tr>
</$list>
</table>

* The first $list widget retrieves ONE "Job Number" tiddler and uses it to display the headings (the index names).  Note the use of "limit[1]" so that only one row of headings is shown.
* The second $list widget then retrieves ALL "Job Number" tiddlers and displays a row for each tiddler, showing the index *values*.

Q.E.D

Matthew Petty

unread,
Mar 28, 2016, 3:57:23 PM3/28/16
to TiddlyWiki
Eric,
Thanks again for your clear explanation and patience!
1. Transclude instead of view - of course, makes sense.
2. I did see the sort option, but couldn't figure out what should go in the brackets. Then you showed me that nothing goes in the brackets - the only available sorts are alphabetical, or reverse. So I renamed my indexes to have numbers, so they sort alphabetically how I want them: jn_01_company, jn_02 etc
3. Aha! I wasn't aware of the limit operator. Clever solution.

My table now shows what I want, and I easily add more rows, and create that macro if I want.

I was also able to use edit-text widgets to be able to edit the values directly.

Thanks again, you're most kind.
Best regards,
Matthew Petty
+971 56 622 1318
Reply all
Reply to author
Forward
0 new messages