Not as “pretty” as actual “if
” and “else
”, but how about this:
<$vars tiddlerCount={{{ [all[tiddlers]count[]] }}} >
<$macrocall $name=SetSessionStorageItem k="tiddlerCount" v=<<tiddlerCount>>/>
</$vars>
<$list filter={{{ [<GetSessionStorageItem k:"tiddlerCount">compare:number:lt[12]] }}}>
<<currentTiddler>> is less than 12
</$list>
<$list filter={{{ [<GetSessionStorageItem k:"tiddlerCount">compare:number:gt[12]] }}}>
<<currentTiddler>> is greater than 12
</$list>
This is a ridiculous example, but it showcases this point: A slow/complicated filter happens just once.
The value is stored in session storage.
The subsequent “if
” and “else
” list widgets then have quick filters to evaluate, taking advantage of the temporary value in session storage.
To try that code, create a new tiddler in this TiddlyWiki which has the SetSessionStorageItem and GetSessionStorageItem macros.
Aside: take a moment to study the “Fibonacci Series” tiddler. This is all about using session storage to mimic true “variables” as we would have in a programming language.
EDIT: For that referenced TiddlyWiki instance:
Even more savings when a “costly” filter would normally be evaluated three times, here just evaluated once. SetSessionStorageItem and GetSessionStorageItem are so fast that, I think, they don’t matter.
<$vars tiddlerCount={{{ [all[tiddlers]count[]] }}} >
<$macrocall $name=SetSessionStorageItem k="tiddlerCount" v=<<tiddlerCount>>/>
</$vars>
<$list filter={{{ [<GetSessionStorageItem k:"tiddlerCount">compare:number:lt[24]] }}}>
<<currentTiddler>> is less than 24
</$list>
<$list filter={{{ [<GetSessionStorageItem k:"tiddlerCount">compare:number:gt[24]] }}}>
<<currentTiddler>> is greater than 24
</$list>
<$list filter={{{ [<GetSessionStorageItem k:"tiddlerCount">compare:number:eq[24]] }}}>
<<currentTiddler>> is equal to 24
</$list>
(I don’t know what’s up with the funky syntax highlighting)