Here you can see it is easy to make a filter increasingly specific through the addition of as many Not qualifications to a very deep level.
If we can phrase a filter this way and use the content or the emptyMessage to respond to the then/else cases we are using an if/then/else.
now with 5.3.x we can move a large set of not filters into a function, or custom operator.
\function is.active() [!tag[done]!has[done-date]!has[archived-date]]
filter="[all[tiddlers]is.active[]]"
OR
filter="[all[current]is.active[]]"
Another approach is to have two list or reveal widgets, with two different filters in use, one produces a result for the then case, the second the exact opposite for the else case.
I will output a list of tiddlers (in this case: search for tiddlers according the input) → works fine
for the output I use a template (= $:/core/ui/ListItemTemplate_published_long) showing the title, a “private” date-field (=published) and the tags of that tiddler → works fine
If a tiddler has no “private” date-field (=published) and no tag, the output looks like
My question is:
How do I display only the title (remove in the output list) if the tiddler has no tag?
we don’t have $ifbut we have $list; the strategy is “show that part only if the tiddler has at least a tag”, or in tiddlywiki-filter-ese, unless is untagged.
In your case, you should put the second, top-level span inside a second $list, like this:
For the sake of novices arriving at this thread wanting to learn how to conditionally display something within a tiddler, it may be useful to encourage the habit of appending limit[1] before closing the filter and appending variable="" or variable=null to the list widget.
In this particular case it makes no difference, because this filter returns exactly the current tiddler (or none at all). But often we want some element to display only when (for example) some other tiddler[s] tag this one. And then we’ll need a bit more caution:
<$list filter="[<currentTiddler>tagging[]limit[1]]" variable=null>
{{{ [<currentTiddler>tagging[]count[]] }}} tiddlers tagging this one
</$list>
Without limiting the filter to one result, and specifying the null variable for the list, the list would evaluate separately for each tiddler tagging this one, and never include the intended content for the current tiddler…
This caveat is for folks who share OP’s same intuitive goal — “All I want to do is conditionally display this part” — but who would be misled by trying to adapt the concise solution offered by @jerojasro.
(Yesterday, after offering a 3-minute whirlwind background beyond certain world events to my curious teen, the kid said with a wink, “Wow, are you a teacher or something?” Yes. And whether for better or for worse, I tend to linger over nudging a forum like this so it serves as a teaching resource beyond addressing the OP’s case.)
Although the <% if %> syntax is technically a “shortcut” (since it was possible to achieve the same results before), it makes it much easier to handle this common kind of need.
Using this conditional shortcut syntax also makes it less confusing for others (and one’s own future self, perhaps) to read and troubleshoot this kind of technique. The “if/else” pattern of thought can feel so different, intuitively, from the <$list> technique that we needed to employ before.
Still, there are many plugins and example solutions out there that predate the conditional shortcut syntax, so it’s helpful to become familiar with how the list widget can display things conditionally (and is still doing that work, behind the scenes).