List each tiddler twice in a filter

My wiki has several tiddlers tagged ‘article’. Each of these tiddlers have p0-date, p0-format, p1-date, p1-format fields. The dates refer to the date on which it was used and the formats refer to the format used on that date.

I want to draw up a list that looks like:

Title       Date        Format
Article1    2022-08-17  Text
Article2    2022-08-19  HTML
Article1    2022-08-21  HTML
Article2    2022-08-23  Text

Each article appears twice — once for p0-date and once for p1-date. When p0-date is used, po-format is used and similarly for p1-date. Also the list is sorted on the date — irrespective of whether it is p0-date or p1-date.

What filter expression do I use?

Here’s an element of an answer:

You can get the results of two filter run expressions to be appended without deduplication using the = run prefix. For instance, if the two runs have the same output, applying a :sort run at the end of the filter expression will co-locate the results, listing them twice each.

e.g. {{{ [!is[system]] =[!is[system]] :sort:string:casesensitive[{!!title}] }}}

In your case, I would use the <$list> widget instead of the filtered transclusion, and you will then need to build a table and use the <<currentTiddler>> variable to output the tiddler title, and other variables for the other information such as the date.

I am not exactly sure how you would do the secondary sort, but you may be able to get there with a nested list (a first level list to sort the titles, listing results only once, then a secondary list with a filter containing <currentTiddler> to output and sort the dates, storing the result into a different variable.) Alternatively, if you know there will only be two date fields, a simple filter expression within the first level list to test if p1-date is later than p0-date, handling both situations by assigning the correct dates to more generic first-date/second-date variables may get you there.

1 Like

A useful reference for double sorting when the sort criteria are a field each http://doublesort.tiddlyspot.com/. Your case is more complex because the secondary sort criteria is a decision made from the values of two different fields.

Is there a tiddler for each article? Or does each tiddler have two article titles? (po-title, p1-title ??).

I just had a brief look at this thread and had an idea I had not before, for double sort and although DoubleSort — sorting lists by two fields looks good.

  • What is we find the maximum length of the first field and pad each with spaces up to that length then concatenate the second field to the end? This would then I believe naturally sort.

Here is a quick attempt, assuming I have understood the requirements correctly:

\define sortfilter()
[split[-----]last[]] :map[<..currentTiddler>split[-----]first[]get<currentTiddler>]
\end

<table>
<thead>
	<td>Title</td>
	<td>Date</td>
	<td>Format</td>
</thead>
<$list filter="[tag[article]!is[draft]]
				:map:flat[fields[]suffix[-date]addprefix[-----]addprefix<currentTiddler>]
				:and[sortsub<sortfilter>]"
>
<$let
	article={{{ [<currentTiddler>split[-----]]}}}
	datefield={{{ [<currentTiddler>split[-----]last[]] }}}
	date={{{ [<article>get<datefield>] }}}
	formatfield={{{ [<datefield>removesuffix[-date]addsuffix[-format]] }}}
	format={{{ [<article>get<formatfield>] }}}
>
<tr>
	<td><$text text=<<article>>/></td>
	<td> <$text text=<<date>>/> </td>
	<td> <$text text=<<format>>/></td>
</tr>
</$let>
</$list>
</table>

n.b. the code assumes the following sequence of characters never appears in a tiddler title: ----- and there may be issues with sorting accurately because of the date format.

1 Like

@Mark_S No. The there is only one article. So, only one article title. No p0-title, p1-title, etc.

@saqimtiaz Thanks. And sorry for replying so late.

Your assumption that there is no ----- in the tiddler title is perfect and there is no problem with sorting.

It captures p0-date and p0-format correctly. But it does not capture p1-date part.

So, there is only one row for each article.

What could be going wrong? How could it be set right?

Please provide some example tiddlers to test against.

@saqimtiaz I have enclosed three tiddlers. It picks up only p1-date and p1-format.

Art1.tid (179 Bytes)
Art2.tid (179 Bytes)
Test Solution.tid (829 Bytes)

1 Like

Screenshot 2022-08-29 at 11.22.06

This is what I see when importing your tiddlers into tiddlywiki.com.
If this is not the desired output, please explain where the difference lies.

@saqimtiaz That is exactly how I wanted it to be! I was seeing only the first and the third row.

Oh! That was because I was using an earlier version of TW.

I have updated it and all is well now.

Thanks. And sincere apologies for the mix-up.