Hide table header of formatted List-Widget ouput

Hello,

I’m a new TiddlyWiki-user and I like it very much.
I even managed to format the output of the list-widget as a table.
This works pretty well, but is there a way to hide the table header when there are no entries?

Here’s the macro which formats the output:

\define Items(filter)
<table class="items-table">
<tr class="items-header">
<td>count</td><td style="text-align:left;">description</td><td>updated</td></tr>
<$list filter="$filter$">
   <tr>
     <td class="items-count">{{!!count}}</td>
     <td class="items-description"><$link/></td>
    <td  class="items-default"><$view field="modified" format=date template="0DD.0MM.YY/0hh:0mm"/></td>
  </tr>
</$list>
</table>
\end

Here’s the macro-call:
<<Items "[tag[item]field:location<currentTiddler>]">>

Maybe there is a way to call the macro only when the filter returns some hits (checking it with count[]), but I’m afraid that with my current (filter-)knowledge doesn’t allow me to do this.
Any help would be very appreciated, thank you.

I’m using TiddlyWiki 5.2.5 with Mozilla Firefox browser 112.0

Try this:

First, add these two lines at the beginning of your macro:

<$set name=items filter="$filter$">
<$list filter="[<items>!match[]]">

and replace this line:

<$list filter="$filter$">

with

<$list filter="[enlist<items>]">
  • The first line invokes the desired filter and captures the resultant item list in a variable named “items”

  • The second line tests the items list to see if it had any contents. If it doesn’t, the remainder of the macro is skipped

  • The replaced line iterates over all the items found to display the table rows.

  • Note that there is no need for closing </$list></$set> at the end of the macro. This is because any “unterminated” widgets are automatically closed when the end of the macro is encountered.

2 Likes

Hi SoonToBeAnExpert :wink: … Welcome!

You should probably use: <$list filter=<<__filter__>> > here. There is a bit of an advantage internally.

You can either use the reveal-widget or the list-widget to “render” optional content. The disadvantage of the reveal-widget is, that it always creates at least 1 HTML DOM element.

So the way to go, if you don’t want to have any output is with the list-widget like so:

\define Items(filter)
\whitespace trim
<$set name="items" filter=<<__filter__>> >
  <$list filter="[<items>!match[]]" variable="ignore">
    <table class="items-table">
      <tr class="items-header">
      <td>count</td><td style="text-align:left;">description</td><td>updated</td></tr>
      <$list filter="[enlist<items>]" >
         <tr>
           <td class="items-count">{{!!count}}</td>
           <td class="items-description"><$link/></td>
           <td  class="items-default"><$view field="modified" format=date template="0DD.0MM.YY/0hh:0mm"/></td>
        </tr>
      </$list>
    </table>
  </$list>
</$set>
\end

<<Items "[tag[HelloThere]]">>

Since calculating complex filters can take much time I did calculate the filter only once, with
<$set name="items" filter=<<__filter__>> > … early in the macro.

Then reusing it with filter="[enlist<item>]", which is fast, since it only needs to get the info from the “items-variable”. … I can use this mechanism 2 times.

  • 1st for the “display nothing if empty” logic: <$list filter="[<items>!match[]]" variable="ignore">
    • See the variable="ignore" … We do not need that variable … the list-widget is used like an “if statement”
    • otherwise it would use currentTiddler
  • 2nd for the “real filter” … <$list filter="[enlist<items>]" >

… That’s basically it. … Hope that helps.

Have fun!
mario

2 Likes

Thank you Eric, works like a charm!
Exactly what I like to achieve.

Hi Mario,
thank you for your detailed reply!

I’m afraid that I wouldn’t be an expert soon, I think this could take a BIT longer :wink:
Although I’m into programming, too, TiddlyWiki is “another class” and I think that most of the times I’m thinking to complicated about solutions in TiddlyWiki.

What I have learned today is:

  1. Don’t torture, ask a question and save time. this problem has kept me busy the whole weekend.
  2. Filters are much more important than I thought at the first sight
  3. TW has a great user community :slight_smile:

My first contact with Tiddlywiki was at the end of January and now I’m wondering how I didn’t found it earlier?
This is a masteriece of software and flexibility and each day I find new possibilities. Easy to learn, but hard to master. I’m simply overwhelmed.

Have a nice day!

Best,
Roland

P.S.: Thank you for your expert tips for “calculating complex filters”

5 Likes

Could you expand on that, or point to an earlier discussion about it? I’m very curious to learn such things!

You may try dynamic tables from Shiraz!

Thank you for the hint, Mohammad.
I have actually installed this on another wiki and it is a great plugin.
But in this wiki (where I wanted to hide the table headers) I tried to solve this without any external help (plugins), i.e. only with the on-board means of the Tiddlywiki.
(and I failed :sweat_smile:)
But thanks to the help of Eric and Mario, the solution was easy again.