[Question] Lists of tiddlers filtered on two columns into a table

57 views
Skip to first unread message

arm...@gmail.com

unread,
Mar 30, 2022, 6:00:55 AM3/30/22
to TiddlyWiki
Hi,

I am stuck on a basic question and would like to know your point of view.

What would be your approach to create an html table with two columns, the first to list all tiddlers labelled with "a" and the second to list all tiddlers labelled with "b", but that each tidler only appears once and is not duplicated?

I started with this code but evidently it doesn't work as I would like. If i have two tiddlers tagged with "a" and a tidller tagged with "b",  the tiddler tagged with "b" so appears on the first and on the second row.

```
<table>
<th >Tag_a</th><th >Tag_b</th>
<$list filter="[!is[system]tag[a]sort[title]]" variable="taga">
<$list filter="[!is[system]tag[b]sort[title]]" variable="tagb">
<tr>
<td><$link to=<<taga></$link></td><td><$link to=<tagb></$link></td>
</tr>
</$list>
</$list>
</table>
```
Any help would be appreciated, thank you !

Charlie Veniot

unread,
Mar 30, 2022, 7:16:41 AM3/30/22
to TiddlyWiki
If a tiddler is in column a and in column b, and that tiddler should only appear once, 

does it mean that tiddler does not appear at all ,  and if not then which column should show that tiddler ?

That aside, <$list> are like loops in programming.  For each item in the first loop, that one item will get processed for every item that is the second loop.

Every tagb item is going to get processed once for every taga item.  So you are going to get repeats of every tagb.


Start with this and then we can work on what to do with items that are tagged both taga and tagb.


<table>
<tr><th >Tag_a</th><th >Tag_b</th></tr>
<tr>
<td>

<$list filter="[!is[system]tag[a]sort[title]]" variable="taga">
<$link to=<<taga></$link>
</$list>
</td>
<td>

<$list filter="[!is[system]tag[b]sort[title]]" variable="tagb">
<$link to=<<taga></$link>
</$list>
</td>
</tr>
</table>

Eric Shulman

unread,
Mar 30, 2022, 10:00:04 AM3/30/22
to TiddlyWiki
Give this a try:
```
<$set  name="A" filter="[tag[a]!is[system]sort[title]]">
<$set  name="B" filter="[tag[b]!is[system]sort[title]] -[enlist<A>]">
<$vars rows={{{ [enlist<A>count[]] [enlist<B>count[]] +[maxall[]] }}}>
<table>
   <th>a</th><th>b</th>
   <$list filter="[range[1],<rows>]" variable=row>
      <tr>
         <td><$link to={{{ [enlist<A>nth<row>] }}}/></td>
         <td><$link to={{{ [enlist<B>nth<row>] }}}/></td>
      </tr>
   </$list>
</table>
</$vars>
</$set>
</$set>
```
Notes:
* The first two `<$set>` widgets get the two lists of tagged items.  Note how the second list (`B`) excludes any items that are already in list `A`.
* The `<$vars>` widget finds the length of the longer list, which will be the number of rows in the output table.
* The `<$list>` widget defines a loop that sets the row number, 1 to N
* Then, for each row, we output the nth item in each list

enjoy,
-e

arm...@gmail.com

unread,
Mar 30, 2022, 10:44:07 AM3/30/22
to TiddlyWiki
I've forgot to precise:
In my use case, a tiddler is tagged with either "a" or "b", but not with both tags a + b.

@cj.v:
Thank you for your code, but i obtain only one row contains tiddlers tagged with "a" in the firt column and tiddler tagged with "b" on the second.
However adding <br> after each <$link>, I almost get the expected result :

Tag_a   Tag_b
Tid1_a
        Tid2_b
Tid3_a
Tid4_a
        Tid5_b

This is already a big step forward for me!


@Eric,

Thanks also for your code and notes for my understanding!
When I try it, I only see the table header "a | b" but no rows after that.
Is there a way to debug what is in the "rows" variable ?

Charlie Veniot

unread,
Mar 30, 2022, 10:53:46 AM3/30/22
to TiddlyWiki
Add a <br> after each </$link>

Charlie Veniot

unread,
Mar 30, 2022, 10:54:50 AM3/30/22
to TiddlyWiki
Arg!  Premature send.

I wanted to add about step forward:  good stuff !

Eric Shulman

unread,
Mar 30, 2022, 10:58:15 AM3/30/22
to TiddlyWiki
On Wednesday, March 30, 2022 at 7:44:07 AM UTC-7 arm...@gmail.com wrote:
Thanks also for your code and notes for my understanding!
When I try it, I only see the table header "a | b" but no rows after that.
Is there a way to debug what is in the "rows" variable ?

Just before the `<table>` element, add:
```
LIST A=<<A>><br>
LIST B=<<B>><br>
ROWS=<<rows>><br>
```


arm...@gmail.com

unread,
Mar 30, 2022, 11:08:11 AM3/30/22
to TiddlyWiki
@Eric,

Variables contents seams to be good:

LIST A=TidA TidC
LIST B=TidB TidD TidE
ROWS=3

But the table still empty

arm...@gmail.com

unread,
Mar 30, 2022, 11:17:25 AM3/30/22
to TiddlyWiki
@Eric,

I've modified  <$list filter="[range[1],<rows> by  <$list filter="[range[1],<<rows>>, and the first row appears correctly with Tid_A (tagged a) on the first column and Tid_B (tagged b) on the second column !
But no more row for the moment...

Eric Shulman

unread,
Mar 30, 2022, 11:47:33 AM3/30/22
to TiddlyWiki
Using doubled angle brackets (i.e., `<<rows>>`) within a filter is definitely not valid syntax, so the filter is most likely just evaluating to `[range[1]]`, which would produce just 1 row of table output (as you observed).
What version of TiddlyWiki are you using?  The `range[1],<var>` filter syntax was introduced in TW5.2.0.

arm...@gmail.com

unread,
Mar 30, 2022, 12:01:56 PM3/30/22
to TiddlyWiki
Oh i did not think to that !
That's true, I was in old version 5.1.2. Now i have upgraded my tiddlywiki to 5.2.2 and your solution works like a charm!

Thank you very much Eric
Reply all
Reply to author
Forward
0 new messages