How to limit a list by entered year

Hello forum,

content of ‘published’ field is eg. ‘2021.10.12’.

Goal: show me all tiddles of year eg. 2021 by using th published field - like:

<span style="color:rgb(255, 201, 102)" >Zeige für das Jahr: </span> 
<$edit-text field=selection color:rgb(255,201,102) placeholder=Wähle.../>
<style>
div.liste {
font-size: 0.55em;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  grid-column-gap: 0.8em;
}
</style>
<div style="column-count:2;column-rule: 1px solid; color:rgb(204, 204, 255);">
<div class="liste">

<div class="grid-2">
<$list filter="[!is[system]!sort[published]]">
<span style="color:rgb(144, 238, 144)" ><$transclude field='erstellt'/></span>
<div>
<$link/>&nbsp; <small> aus Gruppe:&nbsp;
<span style="color:rgb(255, 201, 102)"><$view field="tags"/>

Thanks for help.

{{{ [all[tiddlers]] :filter[get[published]split[]first[4]join[]] +[sort[published]] }}}

You can replace all[tiddlers] with any smaller set of tiddlers that you’d like to consider for this treatment. I assume you want to sort by date within the year, but you can leave that part off if you don’t.

Side note: you might want to consider using TiddlyWiki’s date format (docs, Grok TiddlyWiki) instead of your dot-separated format – this way you’ll be able to ask TiddlyWiki to do things like “find all tiddlers with the published date in the last 2 years.”

Thanks @sobjornstad for feeback.

Typing in the year (see screenshot) will fill the ‘selection’ field with the entered year - eg. 2021.

This code

{{{ [all[tiddlers]] :filter[get[published]split[]first[4]join[]] +[sort[published]] }}}

will not do that, and I’m loosing the fields ‘erstellt’ and ‘tags’ ind the output list.

To clarify:
Each tiddler has a field: ‘erstellt’ with long date format eg. ‘29. Dezember 2021’ and a corresponding ‘published’ field with ‘2021.12.29’.

‘created’ might be today…

Any idea, how to build the <$list filter= ?
Thanks

Whoops, I left out the most important step! It should say

{{{ [all[tiddlers]] :filter[get[published]split[]first[4]join[]match{!!selection}] +[sort[published]] }}}

Also, sorry if this wasn’t clear – I’m just supplying the filter you need. You are supposed to put it in the $list widget’s filter attribute, like

<$list filter="[all[tiddlers]] :filter[get[published]split[]first[4]join[]match{!!selection}] +[sort[published]]">

By the way, the snippet you quoted is missing the closing </$list> tag. It sort of doesn’t matter in this case since TiddlyWiki inserts missing closing tags at the end of the tiddler, but it would be a good idea to add it to avoid issues if you end up adding something to the end of the tiddler later.

With this changes I got no output anymore…

(My additional changes are marked in yellow)

It looks right to me and the filter worked for me. Can you export a couple of tiddlers that this should match, as well as the one you’re working on, and attach them here?

I don’t think this is causing the problem, but you do appear to be missing a closing </small> and a </span> and several </div>'s too – go through and double-check that you have a closing tag for each opening tag.

This is the corrected code with exported test tiddlers: (still no output)

<span style="color:rgb(255, 201, 102)" >Zeige für das Jahr: </span> 
<$edit-text field=selection color:rgb(255,201,102) placeholder=Wähle.../>
<style>
div.liste {
font-size: 0.55em;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  grid-column-gap: 0.8em;
}
</style>
<div style="column-count:2;column-rule: 1px solid; color:rgb(204, 204, 255);">
<div class="liste">

<div class="grid-2">
<$list filter="[!is[system]] :filter[get[published]split[]first[4]join[]match{!!selection}] +[!sort[published]]">
<span style="color:rgb(144, 238, 144)" ><$transclude field='erstellt'/></span>
<div><$link/>&nbsp; <small>aus Gruppe: </small>&nbsp;
<span style="color:rgb(255, 201, 102)"><$view field="tags"/></span></div>
</$list>
</div>
</div>

testtiddlers.tid (229 Bytes)

It’s working for me:

2021 doesn’t get any results, but that’s because the .tid file you sent doesn’t contain a tiddler with a year of 2021.

In your test tiddler, “The last one”, the published field has a value of “2020.12.21”, but your snapshot shows that your input (the value to match) was entered as “2021”. Thus, there is no output. Entering “2020” does produce output.

Also, note that you can simplify the filter syntax by using prefix{!!selection}, like this:

<$list filter="[!is[system]] :filter[get[published]prefix{!!selection}] +[!sort[published]]">

Note that you can simplify the filter syntax by using prefix{!!selection}

I like this approach! It’s only guaranteed to work right for the next 8,000 years or so, though. :wink:

Hi @EricShulman

Yes, there are Tiddlers from every year. Entering

  • 2021 → should list only tiddlers published 2021
  • 2020 → should list only tiddlers published 2020

The new filter doesn’t work:

With the code you gave us, both my filter and Eric’s work as described, at least in my wiki. There must be something different in your other tiddlers compared to the sample tiddler you provided, or in your wiki’s code or settings.

Is it possible you have an old version of TiddlyWiki? :filter was introduced in 5.1.23 (I think?), so if your version is older than that you might be getting bad results because of that.

Edit: The bug I referenced in an earlier version of this post was in subfilter, not in :filter.

2021 doesn’t get any results, but that’s because the .tid file you sent doesn’t contain a tiddler with a year of 2021.

Strange - exported Tiddler are

grafik

Exporting in .tid format only exports a single tiddler, so we only got one of them (The last one). But I created other tiddlers with different published values and it still worked fine, so that shouldn’t be the issue.

If you export these three tiddlers in JSON format (so you get them all) along with your search tiddler and paste them into an empty.html on your own, what happens?

downloaded an emty.html from https://tiddlywiki.com/
→ imported testtiddlers.json (801 Bytes)
→ add code Zusammenfassung aller Inhalte (Datum).json (1020 Bytes)

→ Filter doesn’t work…

OK, I think I found the problem – in 5.2.0, the :filter prefix started modifying currentTiddler to match the current item being filtered, so {!!selection} is referring to the selection field on the tiddler you’re searching for, rather than on the tiddler containing the search the user has entered. I haven’t slung enough filters around in 5.2 yet to remember this.

You can fix it by wrapping the $list widget in:

<$set name="selection" value={{!!selection}}>
</$set>

…and then replacing {!!selection} in the filter with <selection>.

I am baffled on why it worked for both Eric and me in the wikis we tried it in, but not in empty.html (for either you or me), though, which suggests there is something I am still not quite understanding.

like this? - still not ok - sorry

  1. The variable defined by the <$set> is only valid until the matching </$set>. Thus, you need to moved the </$set> down so it is properly nested in between the closing </div></div> sequence.

  2. In the filter, you need to change from using {!!selection} (a field transclusion) to using <selection> (a variable reference).

Thus, the code should be:

<div class="liste">
<$set name="selection" value={{!!selection}}>
<div class="grid-2">
<$list filter="[!is[system]] :filter[get[published]prefix<selection>] +[!sort[published]]">
<span style="color:rgb(144, 238, 144)" ><$transclude field='erstellt'/></span>
<div><$link/>&nbsp; <small>aus Gruppe: </small>&nbsp;
<span style="color:rgb(255, 201, 102)"><$view field="tags"/></span></div>
</$list>
</div>
</$set>
</div>

Thats it - thanks for your effort @EricShulman @sobjornstad - very nice!