Showing a field if it exists and is not blank

53 views
Skip to first unread message

David

unread,
Apr 9, 2020, 11:51:44 AM4/9/20
to TiddlyWiki
I'm inside a <$list> where the iterator var is "item".  This code is correctly displaying the value of the subtitle field for the tiddler in question.

<$transclude tiddler=<<item>> field="subtitle" />

But I'd also like to wrap it in a CSS class, so this now works just fine....

<span class="subtitle"> ... <$transclude tiddler=<<item>> field="subtitle" /></span>


But the final tweak is to only show that span when there is actually text in the field.  If it's blank or not defined, I'd like not to display the span or "..." separator, and of course there won't be text to show for the field either. 

I tried the Reveal widget but couldn't figure that out quite right.

Jalen MichalsLevy

unread,
Apr 9, 2020, 12:00:57 PM4/9/20
to TiddlyWiki
I am no expert, but you could try the following: 

<$reveal type ="nomatch" stateTitle =<<item>> stateField ="subtitle" text =""> <span class="subtitle"> ... <$transclude tiddler=<<item>> field="subtitle" /></span> </$reveal>

Lemme know how it works!

Mat

unread,
Apr 9, 2020, 12:52:45 PM4/9/20
to TiddlyWiki
Try this

<$list filter="[<item>has[subtitle]]">
@@.myclass
{{!!subtitle}}
@@
</$list>

<:-)

TonyM

unread,
Apr 9, 2020, 9:21:46 PM4/9/20
to TiddlyWiki
Backing up what Mat suggested the has[fieldname] will only show if the fieldname has a value, if you wanted to know if it existed but with no value you can use has:field[fieldname]] I know that is not what is asked for here, but it could have being.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages