How to show text conditionally when the field is no empty?

250 views
Skip to first unread message

yrosgi L

unread,
May 11, 2020, 8:51:14 PM5/11/20
to TiddlyWiki
I have tried to add the source field to the view template with following text:

source: {{!!source}}

when the source field is empty, it just display "source:" at the bottom.
I hope that the snippet above only display while source field is no empty.
How can I do that?

Thanks.

Eric Shulman

unread,
May 11, 2020, 9:37:47 PM5/11/20
to TiddlyWiki
There are several ways to test to see if there is a source field.  Here's one:

<$list filter="[<currentTiddler>has[source]]">
   source: {{!!source}}
</$list>

The has[...] filter checks to see if the specified field is *non-empty*.  If the field does not exist or is empty, the body of the $list widget is completely skipped.  Thus, the "source:" label is only displayed when there is an actual value to show.

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)

TonyM

unread,
May 11, 2020, 9:42:22 PM5/11/20
to TiddlyWiki
yrosgi

I see Eric got in first, but since I wrote this.

<$list filter="[all[current]has[source]get[source]]">
Source: <
<currentTiddler>>
</$list>

This should work for you
  • This operates on the current tiddler, and would work well in the view template
  • has[source] with return only non blank content, as opposed to has:field[source] which will return even a blank field if it exists.
  • Since your filter capture field with the source field containing content you may as well use get[source] to retrive the value
Regards
Tony

yrosgi L

unread,
May 12, 2020, 6:25:38 AM5/12/20
to TiddlyWiki
Thank you all above, the Eric's one seems good.

yrosgi L

unread,
May 13, 2020, 7:22:58 AM5/13/20
to TiddlyWiki
Hi, Eric. May I ask one more detail about the $list filter that how to check whether a tiddler has backlinks?

Thanks

在 2020年5月12日星期二 UTC+8上午9:37:47,Eric Shulman写道:

Soren Bjornstad

unread,
May 13, 2020, 8:12:04 PM5/13/20
to TiddlyWiki
[all[current]backlinks[]]

should do the trick. The $list widget will display its contents if and only if there are results in the filter, so in this case you get nothing if there are no backlinks.

If you're not sure where backlinks[] comes from, the filter operators tiddler in the documentation is a great reference.

yrosgi L

unread,
May 14, 2020, 12:26:57 AM5/14/20
to TiddlyWiki
Thanks!

在 2020年5月14日星期四 UTC+8上午8:12:04,Soren Bjornstad写道:

yrosgi L

unread,
May 14, 2020, 3:37:40 AM5/14/20
to TiddlyWiki
after I tried this filter, I found that it will repeat the content while filter get more than one element. So I add first[] filter and make it works :)


在 2020年5月14日星期四 UTC+8上午8:12:04,Soren Bjornstad写道:
[all[current]backlinks[]]

Reply all
Reply to author
Forward
0 new messages