Hide $count if zero

131 views
Skip to first unread message

Joe Bush

unread,
Jul 25, 2018, 6:05:23 PM7/25/18
to TiddlyWiki
In part of my $list tree I display a $count of the children of a given tiddler. Is there a way to hide or not display the <$count> element if it returns 0?

TonyM

unread,
Jul 25, 2018, 7:56:31 PM7/25/18
to TiddlyWiki
Joe,

Try using count as a filter operator on a list

<$list filter="[yourfilter]count[]" variable=result>
<<result>>
</$list>

In the above case result will display the count, but nothing will show if nothing or 0 items are in the result.

And you could extend this with the emptyMessage (not what you are asking for)

<$list filter="[yourfilter]count[]" variable=result emptyMessage="none">
<<result>>
</$list>

Regards
Tony

Joe Bush

unread,
Jul 28, 2018, 12:18:29 PM7/28/18
to TiddlyWiki
When I use

<$list filter="[tag<currentTiddler>count[]]" variable=result emptyMessage="none">
<<result>>
</$list>

I still get zeroes as the return. I added the empty message and it doesn't show up, returns 0 instead.

Mark S.

unread,
Jul 28, 2018, 1:17:18 PM7/28/18
to TiddlyWiki
A filter ending in count[] will never be empty because zero is a number! But (at least in my test) you can subtract out the 0:

<$list filter="[tag<currentTiddler>count[]] -[[0]]" variable=result emptyMessage="none">

Then it will return "none" for the zero count.

-- Mark

Diego Mesa

unread,
Jul 28, 2018, 1:48:43 PM7/28/18
to TiddlyWiki
Hey mark,

Good idea. Why doesnt using a reveal and comparing against "0" work? 

Diego

Mark S.

unread,
Jul 28, 2018, 2:03:02 PM7/28/18
to TiddlyWiki
That could work too, though it would involve making an extra tiddler to put the comparison zero and more widgets:

<$list filter="[has[yourfilter]count[]]" variable=result >
<$reveal state="zerostate" type="match" text=<
<result>>>
NOTHING HERE FOLKS!
</$reveal>
<$reveal state="zerostate" type="nomatch" text=<
<result>>>
<
<result>>
</$reveal>
</$list>

(assumes you've made "zerostate" a tiddler populated with a "0".

-- Mark

Joe Bush

unread,
Jul 28, 2018, 2:38:55 PM7/28/18
to TiddlyWiki
Thanks Mark. This worked like a charm:

<$list filter="[tag<currentTiddler>count[]] -[[0]]" variable=result>
<<result>>
</$list>

On Saturday, July 28, 2018 at 12:17:18 PM UTC-5, Mark S. wrote:

Diego Mesa

unread,
Jul 28, 2018, 4:00:58 PM7/28/18
to TiddlyWiki
Hey Mark,

Thanks for this! Just to confirm, state can't take a variable directly right? Like:

<$reveal state=<<result>> type="nomatch" text="0"
<<result>>
</$reveal>


I tried it but it didnt work for me so Im just making sure Im not doing anything silly.

Mark S.

unread,
Jul 28, 2018, 4:28:39 PM7/28/18
to TiddlyWiki
AFAIK state can only take a text reference. The Reveal widget acts the most like structures in other languages that people are familiar with, so it would be useful if it could make variable/variable comparisons as well.

-- Mark

Eric Shulman

unread,
Jul 28, 2018, 6:30:43 PM7/28/18
to TiddlyWiki
On Saturday, July 28, 2018 at 1:28:39 PM UTC-7, Mark S. wrote:
AFAIK state can only take a text reference. The Reveal widget acts the most like structures in other languages that people are familiar with, so it would be useful if it could make variable/variable comparisons as well.
On Saturday, July 28, 2018 at 1:00:58 PM UTC-7, Diego Mesa wrote:
Thanks for this! Just to confirm, state can't take a variable directly right? Like:
<$reveal state=<<result>> type="nomatch" text="0"
<<result>>
</$reveal>

In the <$reveal> widget, you can use default=... parameter to specify a value from a variable, as documented:

defaultDefault value to use when the state tiddler is missing

Thus, OMIT the state=... param, and use default=... instead:
<$reveal text=<<result>> type="nomatch" default="0">

enjoy,
-e


TonyM

unread,
Jul 28, 2018, 8:27:37 PM7/28/18
to TiddlyWiki
Just a tip for all.

When you want to put a variable in a widget parameter use the macrocall widget instead to invoke the widget then you can pass variables.

Regards
Tony

Diego Mesa

unread,
Jul 29, 2018, 10:33:44 AM7/29/18
to TiddlyWiki
Thank you Eric! Each time you post this I a reminded of all the other times you post this! Thank you for being patient and persistent.

Diego
Reply all
Reply to author
Forward
0 new messages