Background
The list-search is a macro allows to search in a filtered list of tiddlers through a search box (e.g. text box).
Originally it was developed by Tobias Beer. Later Shiraz from kookma, adopted an improved version of Tobias list-search macro and other users also developed their own version (see for example @DaveGifford list-search macro).
KISS implementation
This is a KISS (keep it simple, stupid) implementation. Thanks to subfilter operator which allows to pass a string variable as filter to it.
\define list-search(filter)
<$edit-text field="search" placeholder="enter keywords or regex pattern to search" size="50"/>
<$set field=search name=term tiddler=<<currentTiddler>> >
<$list filter="[subfilter<__filter__>]" template="$:/core/ui/ListItemTemplate" />
</$set>
\end
Example i
<<list-search "[!is[system]regexp<term>limit[25]]" >>
Example ii
<<list-search "[tag[Learning]search:title<term>]">>
How it works
- An
$edit-textwidget gets the search keywords or regex pattern from user - The keywords/patterns are stored in
searchfield of current tiddler - The
$setwidget retrieves the user input - The
$listwidget simply uses the filter, dynamically created, and shows the results if any!
Magic
- The filter is passed in Example i is
[!is[system]regexp<term>limit[25]]but the term is not existed at the scripting time, and it will be created at run time. The same is true for Example ii. Thesubfilterreceives the dynamic filter as string variable and runs it!
To give a try
-
download kiss-macro-list-search.json (932 Bytes)
-
drag and drop
kiss-macro-list-search.jsonfrom step 1 into https://tiddlywiki.com -
open Example i and Example ii and try to search
References
- Dynamic Filters - Discussion - Talk TW (tiddlywiki.org)
- Search Macro: How Not to Use Text Substitution? - Discussion - Talk TW (tiddlywiki.org)
- tb5 — list-search (tobibeer.github.io)
- Shiraz 2.7.6 — create stylish contents in Tiddlywiki (kookma.github.io)
- Special tanks to @saqimtiaz and @pmario
Update ii: Example ii corrected!



