How do I filter by date (of creation) for transclusion list?

689 views
Skip to first unread message

Lost Admin

unread,
Dec 4, 2017, 12:00:28 PM12/4/17
to TiddlyWiki
Hi all,

I started using TiddlyWiki as a tool to quickly make a small website. I would like to make an announcements/news section. I figured using the Journal tiddler technique would make a good way to generate a news list. It sorts by date and I can easily use the table-of-contents macro to generate a page listing all the news tiddlers.

I would also like to have a subset of the most recent news show up on the default tiddler (transcluding them). I can't figure out how to make a filter to generate the list of tiddlers to transclude. Is there an easy way to do this? I'm thinking something like:

All journal tiddlers that were created in the last month. Possibly further filtered by only displaying the most recent 3 in that list if there are more than 3 entries in that list.

TonyM

unread,
Dec 4, 2017, 6:08:19 PM12/4/17
to TiddlyWiki
Lost Admin,

A quick answer thus not comprehensive, if you create a list that shows the tiddlers you want in the order you want you can then use limit[3] the filter operand to show the first three. https://tiddlywiki.com/#limit%20Operator%20(Examples)

<$list filter="[tag[ScratchPads]limit[2]]">
<h2>{{!!title}}</h2>
<$transclude mode=block/>
</$list>

The above also creates a title for each tiddler and transcludes it.

Regards
Tony

Lost Admin

unread,
Dec 5, 2017, 11:52:57 AM12/5/17
to TiddlyWiki
Thanks. Not quite what I wanted, but still a good way to handle it.

BurningTreeC

unread,
Dec 5, 2017, 12:17:02 PM12/5/17
to TiddlyWiki
\define getTiddlerTitle()
<$list filter="[all[tiddlers]field:created[$(currentYear)$$(currentMonth)$$(currentTiddler)$]]">

{{!!title}}

</$list>
\end

<$vars currentMonth=<<now MM>> currentYear=<<now YYYY>>>

<$list filter="[all[tiddlers]!has[draft.of]!sort[created]get[created]removeprefix<currentYear>removeprefix<currentMonth>limit[3]]">
<<getTiddlerTitle>>
 </$list>
 
 </$vars>

Lost Admin

unread,
Dec 5, 2017, 2:36:15 PM12/5/17
to TiddlyWiki
I understand some of what is going on there. You define a macro that prints the titles of all tiddlers with a creation date that matches 3 variables (currentYear, currentMonths, and currentTiddler).

Then you define currentYear and currentMonth to be (as the name suggests) the current year and current month.

The last filter loses me bit. It starts out building a list of all non draft (not being edited) tiddlers, all[tiddlers]!has[
draft.of]

Then, I think it sorts by the created field (so I get most recent at the top of the list). The removeprefix loses me.
The limit[3], I understand. That says only give the first three results.

I'm not sure how this works for notices that went up on say the 30th of the previous month when it is the 1st. Those would be less than a month old but aren't in the current month.

BurningTreeC

unread,
Dec 5, 2017, 3:11:07 PM12/5/17
to tiddl...@googlegroups.com
Ok, I'll explain:

The macro doesn't get called first. You got confused because you watched the top filter first. Start with <$vars

first the currentMonth and currentYear variables are defined.

Then the filter  [all[tiddlers]!has[draft.of]!sort[created]get[created]removeprefix<currentYear>removeprefix<currentMonth>limit[3]  does:

1: all tiddlers not currently open
2: !sort[created]  ... sort by creation date but in reverse order - so the last created are on top of the list. Now the filter shows the creation dates of the tiddlers, not the names. The creation dates have the form: 20171205<hour><minute><seconds><nanoseconds?>
3: removeprefix<currentYear> ... removes the prefix "2017" from the creation dates. if the prefix is not 2017 the tiddler doesn't pass the filter. removeprefix<currentMonth> then removes the prefix "12" . Every tiddler that doesn't have "12" as prefix at that point doesn't pass. then limi[3] chooses the last three.


4. now you have the last three creation dates but without 201712 at the beginning. Just <hour><minute><seconds><nanoseconds>

5. <<getTiddlerTitle>> now calls the macro that is defined on top (macros have to be defined on top of the tiddler).

6. the filter [all[tiddlers]field:created[$(currentYear)$$(currentMonth)$$(currentTiddler)$]]  now filters all tiddlers with creation date $(currentYear)$$(currentMonth)$$(currentTiddler)$ ... currentYear=2017 currentMonth=12 currentTiddler=the filter result from the removeprefix-filter. that is just the creation date without year and month. This filter makes a puzzle.


For your purpose you'll add "tag[Journal]"   ( or your own journal tag  ) after "all[tiddlers]" in both filters

Mark S.

unread,
Dec 5, 2017, 3:31:54 PM12/5/17
to TiddlyWiki
The semi-new 'days' filter is helpful. You can try this on tiddlywiki.com:

<<list-links "[all[tiddlers]!prefix[$]!prefix[Draft]days:modified[-30]!sort[modified]limit[8]]">>

Shows the 8 most recently modified tiddlers (non-draft,non-system) from the last 30 days.

-- Mark
Reply all
Reply to author
Forward
0 new messages