I have two list filters with a preceding line of text, as follows:
Home of:
<$list filter="[all[tiddlers]search:Home<currentTiddler>sort[]]">
</$list>
Place of residence of:
<$list filter="[all[tiddlers]search:residence<currentTiddler>sort[]]">
</$list>
If the filters have no results I would like to hide the preceding text (i.e. hide “Home of:” if there is no result). I could do this in Excel with the “if” function. Can I do something similar here?
Also, I would like to arrange the layout in the tiddler into two columns with “Home of:” in the left column and “Place of residence of:” in the right column
Maybe a Grid CSS might do this, but is there something simpler?
<% if [search:Home<currentTiddler>] %>
<$list filter="[all[tiddlers]search:Home<currentTiddler>sort[]]"/>
<% endif %>
The “if” conditional syntax will process the content as long as there’s a result at all. SInce your list already bumps back out to all tiddlers, you don’t need to worry about which tiddler “fits” the if expression, or what the count is.
Hence the need to join, and then enlist, in order to make use of the actual list rather than first result. (Any reason not to tuck the “sort” into the outer <% if %> expression as well?)
enlist does not seem to be quite so nice as it concatenates all the results into one long string, not even space or preferably comma and space separated.
Just habit! I generally try not to sort lists (including lists stored as variables) until actually needed for display purposes. But in this case, sort won’t apply if there aren’t any results, and if there are results, you’ll want them sorted anyway. So moving it to the outer filter expression should be fine — it just needs to be inserted before the format/join step:
<% if [search:Home<currentTiddler>] +[sort[]format:titlelist[]join[ ]] %>
That’s actually nothing to do with the filter I used; it displays that way because I used a self-closing $list, as @Springer also did in her example. If you want to preserve the one-item-per-line output, you could easily switch back to the “empty” list template you used in your original example:
<$list filter="[enlist<condition>]">
</$list>
Or if you’d prefer comma-separated results, you can do that too: