Before this subject is totally forgotten remember that;
The content of the <$view>
widget is displayed if the field or property is missing or empty.
see https://tiddlywiki.com/#ViewWidget
Try this on tiddlywiki.com
<$view field=modified format="relativedate"/>
<$view field=anotherdate format="relativedate">
emptyMessage
</$view>
In the above since there is no anotherdate instead the the emptyMessage text is displayed.
@jeremyruston for ideas re if/else/nesting and see my next reply for subwidget idea.
So rather than introduce sub widgets consider this;
- It should not overload the list widget because it is just a parameter and setting the template.
Thus;
If we consider the list widget, which has a few ways to specify the template to be used.
Current Examples of the list widget;
<$list filter="[tag[Lists]sort[title]]"/>
<hr>
<$list filter="[tag[Lists]sort[title]]"><<currentTiddler>>, </$list>.
<hr>
<$list filter="[tag[Lists]sort[title]]">
</$list>
<hr>
<$list filter="[tag[Lists]sort[title]]">
Not empty
</$list>
<hr>
<$list filter="[tag[Lists]sort[title]]" template="$:/core/ui/ListItemTemplate">
Does not appear if the template is used
Perhaps this could be used as the emptyMessage template if emptyMessage parameter is not provided but template it.
</$list>
<hr>
above Works on tiddlywiki.com
Slight change to the list widget.
Consider then if the List widget included a message=
parameter as a complement to the emptyMessage=
parameter.
<$list filter="filter" message=<<eachitem>> emptyMessage=<<no items>>/>
However if one of the two parameters are missing then the content of the list widget acts as the template for that.
<$list filter="filter" message=<<eachitem>> >
<<no items>>
</$list>
Or
<$list filter="filter" emptyMessage=<<no items>> >
<<eachitem>>
</$list>
In the above if “message” is not provided the behaviour is not different so this should be backward compatible.
Why?
This would make it very easy to “Nest list widgets” by choosing if the body is the true/false or message/emptyMessage condition. Especially when you want a default action or to handle the “nul” or else case".
For example consider this nest or “case” structure that would be possible.
<$list filter="one two three +[match<my-variable>]]" variable=result>
<$list filter="[<result>match[one]]" message=<<doifone>> >
<$list filter="[<result>match[two]]" message=<<doiftwo>> >
<$list filter="[<result>match[three]]" message=<<doifthree>> >
No valid `result` eg: please provide the my-variable
</$list>
</$list>
</$list>
</$list>
Fore Message and emptyMessage we could use the parameters if and else.