A little confused by default parameter in macro

Hi, I have a macro (code below) and it accepts a paramter that defaults to <<currentTiddler>>. It then displays that parameter followed by a table filtered on tags matching the parameter. When provided a parameter explicitly it works fine. When it defaults, it displays the parameter fine but the filter fails for some reason. Any idea of what I’m messing up would be appreciated.

\define org-table(tagname:<<currentTiddler>>)
$tagname$
<table>
<thead>
<tr>
<th>Family</th>
<th>Type</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
<$list filter="[tag[$tagname$]]">
<tr>
<td><$link /></td>
<td><<org-type>></td>
<td>{{!!summary}}</td>
</tr>
</$list>
</tbody>
</table>
\end

The default parameter value for tagname is literally “<<currentTiddler>>”. It is NOT evaluated.

The reference to $tagname$ on the first line of the macro simply inserts <<currentTiddler>> into the macro output. Then, when that macro output is rendered in the calling context, it gets “wikified” to show the expected tiddler title.

When you use [tag[$tagname$]] in the $list filter parameter, it is also just substituted with <<currentTiddler>>, resulting in [tag[<<currentTiddler>>]], which is not valid filter syntax.

Here’s an alternative approach to using the currentTiddler value as the default for the parameter:

\define org-table(tagname)
<$let tid={{{ [[$tagname$]!match[]else<currentTiddler>] }}}>
<<tid>>
<table>
...
<$list filter="[tag<tid>]">
...
</$let>
\end
  • The initial $let widget uses a “filtered transclusion” to set the tid variable to the passed in $tagname$ parameter value if it’s not blank. Otherwise, it sets the tid variable to the value of the <<currentTiddler>> variable.
  • Note that, within filter syntax, references to the tid variable use SINGLE angle brackets.

-e

Thank you so much for your answer - it was exactly what I needed. And doubly thank you for your detailed explanation which has helped me unpick why I was making the mistake :slight_smile:

1 Like