Empty list substitution in a view template

115 views
Skip to first unread message

Dmitry Skopa

unread,
Aug 1, 2016, 4:37:20 AM8/1/16
to TiddlyWiki
Hello everyone!

I've found very useful to have a list of all related tiddlers (tagged with current tiddler) always visible at the bottom of a current tiddler.

I have a $:/tags/ViewTemplate tiddler with field list-after set to $:/core/ui/ViewTemplate/body and this contents:
 
<$list filter="[all[current]]">
 
<h1>Related:</h1>
 
<ul>
    <$list filter="[all[current]tagging[]sort[modified]]">
     
<li>
        <$link to={{!!title}}><$view field="title"/></$link>
     
</li>
    </$list>
 
</ul>
</$list>

This works the way I want except one thing: I would like to remove "Related:" header when the list is empty. Is it possible?

PMario

unread,
Aug 1, 2016, 9:11:29 AM8/1/16
to TiddlyWiki
Hi,

Not a real solution, but imo a workaround to make the "Related" text more meaningful. ... The list widget has an "emptyMessage" http://tiddlywiki.com/#ListWidget parameter. You can use it, to have a text eg: "-- no related tiddlers --". So users know, what's going on.

-mario

Eric Shulman

unread,
Aug 1, 2016, 9:41:00 AM8/1/16
to TiddlyWiki
On Monday, August 1, 2016 at 1:37:20 AM UTC-7, Dmitry Skopa wrote:
<$list filter="[all[current]]">
 
<h1>Related:</h1>
 
<ul>
    <$list filter="[all[current]tagging[]sort[modified]]">
     
<li>
        <$link to={{!!title}}><$view field="title"/></$link>
     
</li>
    </$list>
 
</ul>
</$list>

This works the way I want except one thing: I would like to remove "Related:" header when the list is empty. Is it possible?

Instead of writing just:
<h1>Related:</h1>
you can enclose it in a <$list> widget like this:
<$list filter="[all[current]tagging[]sort[modified]limit[1]]">
 
<h1>Related:</h1>
</$list>

This <$list> widget uses the same filter syntax as the <$list> widget that actually produces the link output, but with the added "limit[1]".  This effectively turns the widget into a test that says "if the filter results are not empty, show the heading".  Note: you can optimize this filter a bit more by leaving out the "sort[modified]" syntax, since it doesn't affect the test conditions.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
InsideTiddlyWiki: The Missing Manuals

Dmitry Skopa

unread,
Aug 2, 2016, 12:55:42 AM8/2/16
to TiddlyWiki
emptyMessage is a good thing to mark nothing is found, but I'm still have a useless header which I want to avoid

Dmitry Skopa

unread,
Aug 2, 2016, 12:57:39 AM8/2/16
to TiddlyWiki
This works pretty well, thank you. But wouldn't it cause tiddlywiki to run same search routine twice?

Eric Shulman

unread,
Aug 2, 2016, 2:23:09 AM8/2/16
to TiddlyWiki


On Monday, August 1, 2016 at 9:57:39 PM UTC-7, Dmitry Skopa wrote:
This works pretty well, thank you. But wouldn't it cause tiddlywiki to run same search routine twice?

Yes, but this particular search is pretty efficient... "all[current]" is a simple reference to the current tiddler context (which is automatically tracked by the core), "sort[modified]" can be omitted (since you are only testing for non-empty), and "limit[1]" merely truncates the filter result to one item.  Only the "tagging[]" filter has any real lookup processing, and even that is relatively efficient since you are only looking for one specific tag (the current tiddler), so performance is linear, based on the total number of tiddlers.
Reply all
Reply to author
Forward
0 new messages