Count the number of tiddler by tag

I would like to create a summary page for all institutes which count the number colleagues in institute.

Each institute is tagged by Institute with institute name by title. Each colleague is tagged by Institute Name.

This is my current implementation. But it is not working as I expected (i.e. all numbers equal to zero).

<table>
    <tr> 
        <th>Name</th>
        <th># of Colleagues</th>
    </tr>
    <$list filter="[tag[Institute]!has[draft.of]]" >
       <$set name="tiddlertitle" value= {{!!title}} >
        <tr>
            <td><$link to=<<currentTiddler>> /> </td>
            <td><$text text=  {{{ [tag[<tiddlertitle>]!has[draft.of]count[]]  }}}/></td>
        </tr>
        </$set>
    </$list>
</table>

I replace the <tiddlertitle> with real institute name then the script is working.

Thanks for any tips?

1 Like

The brackets surrounding a filter operand are used to indicate how to process the operand value:

  • square brackets for literal text: tag[literaltext]
  • angle brackets for variable references: tag<variablename>
  • curly braces for tiddler field refernces: tag{!!fieldname}

Thus, your filter should use tag<tiddlertitle> instead of tag[<tiddlertitle>]. In addition, there are some ways to further simplify the code, like this:

<table>
    <tr> 
        <th>Name</th>
        <th># of Colleagues</th>
    </tr>
    <$list filter="[tag[Institute]!has[draft.of]]" >
        <tr>
            <td><$link/></td>
            <td><$count filter="[tag{!!title}!has[draft.of]]"/></td>
        </tr>
    </$list>
</table>

Notes:

  • There is no need to get the tiddlertitle as a variable. Instead, you can reference it directly in the filter syntax by using {!!title}
  • The $link widget defaults to the currentTiddler, so you can omit the to=... param
  • You can use the $count widget instead of <$text text={{{ [...count[]] }}}/>

enjoy,
-e

4 Likes

Thanks. I have better understanding about variables now.