Creating a list based on fields from multiple tiddlers

Hello,

I am stuck on the creation of a filter and decided to ask for some help.

I am creating tiddlers that store information about ongoing projects. Among these information should be statement dates. Each project can have 1 or more statement dates (5/6 max).

the fields are named in a standardized way :

  • prefix : date_
  • nameofthetiddler
  • suffix : _X, with X a number from 1 to 6.

And they contain a date written as YYYYMMDD.

I am trying to add a filter/combination of filters that will look for any field with the prefix ‘date_’ and give me both the name of the field and the name of the tiddler containing it, so that i can then access to these informations.

Here is an illustration of what I am trying to generate, for dates stored in tiddlers named Tiddler1 and Tiddler2 :

  • 25 January 2025 : Tiddler1
  • 12 Mars 2025 : Tiddler2
  • 02 June 2025 : Tiddler1

I assumed the way to do this would be to filter all fields with prefix date_ across all tiddlers, and extract both the name of the field and the name of the tiddler.
With these two elements, I would then recover everything I need. Maybe other fields of the tiddler if that’s useful.
But my most functional code is only able to recover the name of the fields, not the name of the tiddlers containing each one of them. I’ll put it at the end of the post, even if it is not functional. All other attempts, end-up giving me an empty list.

Is what I’m trying to do possible ? How could I extract these information ?
Or should I look at an other way to achieve such result ?

my “most functional code” :

<ul>
<$list filter="[all[]fields[]prefix[date]]" variable="field">
<li><<field>> : </li>
</$list>
</ul>

Also, Is there important resources or tutorials I could refer to, in order to better understand filters in tiddlywiki ? (Outside of tiddlywiki.com and Tobibeer’s wiki).

Going by this description, you’re already most of the way there! You just need to nest a second list inside the first to retrieve a list of all tiddlers that have a given field.

<ul>
<$list filter="[all[]fields[]prefix[date_]]" variable="field">
	<li>
		<<field>>:
		<$list filter="[has<field>]" join=", " />
	</li>
</$list>
</ul>

However, this example

makes me think that what you want is not a list of the field names and their associated tiddlers, but a list of all the values of all the fields with the date_ prefix, and then a nested list to display all the tiddlers that contain that date in any date_ field. Is that right?

If so, this is also doable, but it’s significantly more complex, and may get rather slow if you have a lot of this kind of data. If I’m understanding your data structure correctly, I think your field naming conventions are also making things more complicated than they need to be.

So typical field names would look like date_TiddlerA_1, date_TiddlerB_3, etc.?

Is there a reason why the field names need to contain the name of the parent tiddler? This naming scheme will mean you have 1-6 totally unique field names per tiddler, and that will make it much more difficult to filter and search their contents.

If at all possible, I’d really recommend switching to date_1 - date_6 instead. This will cut down on field name bloat significantly and make it much easier to revisit this goal

a list of all the values of all the fields with the date_ prefix, and then a nested list to display all the tiddlers that contain that date in any date_ field

if we only have to search 6 fields, rather than hundreds or thousands. :wink:

I just want to second this reaction by @etardiff … the power of fields is greatly enhanced when you can “xray” across tiddlers to recognize different values of the same field. You can always use filter language and shortcuts (like {{tiddlername!!fieldname}}) to get at the granular specifics of tiddler + fieldname.

There are also other benefits to having a relatively compact “name-space” for fields — such as type-ahead auto-completion of existing field names. This dropdown of suggested field names will begin to feel like a cluttered mess if nearly every user-created fieldname in your wiki is used only once.

Feel free to share more about your project. Often some careful decisions early in the design process (even if they involve some revision of earlier work — and there are good tools for doing that such as Commander) can reap big benefits down the road!

Give this a try:

Note that the following solution uses date field names that do not contain the tiddler titles (i.e., date_1, date_2, date_3, etc), as already suggested by @etardiff and @Springer.

This makes your tiddlers less “brittle”, since you can rename any tiddler without having to change all the field names they contain. It also reduces the “field name space”, which is generally a good idea for overall performance of your wiki.

\define format() [UTC]0DD MMM YYYY

<$set name=tids   filter="[all[]] :filter[<currentTiddler>fields[]prefix[date]]">
<$set name=fields filter="[enlist<tids>fields[]prefix[date]]">
<$set name=dates  filter="[enlist<fields>] :map:flat[enlist<tids>get<currentTiddler>]">

TIDS=<<tids>><br>
FIELDS=<<fields>><br>
DATES=<<dates>>

<ul>
<$list filter="[enlist<dates>sort[]]" variable=thisdate>
<li>
<$text text={{{ [<thisdate>format:date<format>] }}}/>:
<$list filter="[enlist<tids>]" variable=thistid>
{{{ [enlist<fields>] :filter[<thistid>get<currentTiddler>match<thisdate>] :map[<thistid>] }}}
</$list>
</li>
</$list>
</ul>

Notes:

  • The format definition is used later on to show the date output. We need this because the date format includes the [UTC] prefix so that date output is not adjusted for local timezone differences, and we can’t have literal square brackets within the format:date filter parameter, because square brackets are used by the filter syntax as delimiters.
  • Next, we get some lists and save them in variables
    • tids = all tiddlers that have fields with the date prefix
    • fields = all date_n field names that are actually being used
    • dates = field values (dates) contained in all date fields
  • The next 3 lines are only for debugging purposes so you can see the calculated values for tids, fields and dates
  • The first $list widget loops through all dates, sorted in ascending order and sets thisdate
  • For each date:
    • The $text widget outputs thisdate using the previously defined format
    • Then, for each tiddler that has fields with a date prefix:
      • For each date_n field in that tiddler, if that field’s contents matches thisdate, show the tiddler name (thistid)

Let me know how it goes…

enjoy,
-e

Thank you @etardiff and @EricShulman , I tried both of your solution, and they work.
And thank you for the explanations. I think it will improve my understanding of filters and their logic. One more step toward the moment were I won’t need to ask stupid questions on this forum… :joy:

Etardiff : my idea was that with both field name and tiddler name, you can recover the values from the field, and if needed, any other field of this identified tiddler.

For the names… I normally use the same field names across every tiddler, but one of the first filter I wrote for this project was confusing the names. It would create an entry for every “date_1”, but give all of them the value of the first in the list. I opted for unique names to avoid the problem. I wasn’t sure if I should try to get back to uniform names, or if I could find a way to extract the tiddler name from the field name by removing both the prefix and the suffix.
So mistakes over mistakes, that’s the reason.

@Springer It’s for a tiddler containing an interface that control a filter via fields values. This filter then display a resume of the key information of each corresponding tiddler. What is being filtered are Call for Projects and Public Funding Offers open for companies, cities and universities of my region. For now, it browse via a few preset categories (fields), and up to 4 tags.
I am trying to add more categories (the easy parteasy) and additional way of displaying datas.
One of them was a filter by statement dates, and I got stuck on the first step : recovering the dates and the name of the corresponding tiddlers. I think I’ll be able to carry-on with what I already knew and what I learned here.