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

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 !

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 ?
  • rather (reading your post again): which column should not show the duplicate?

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>

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

1 Like

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
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 ?

Add a
after each </$link>

Arg! Premature send.

I wanted to add about step forward: good stuff !

Just before the <table> element, add:

LIST A=<<A>><br>
LIST B=<<B>><br>
ROWS=<<rows>><br>

@Eric,

Variables contents seams to be good:

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

But the table still empty

@Eric,

I’ve modified <$list filter="[range[1], by <$list filter="[range[1],<>, 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…

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.

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