Using variables and regex in a macro with a list filter.

27 views
Skip to first unread message

Christian Macedo

unread,
Sep 10, 2019, 8:52:57 AM9/10/19
to TiddlyWiki
I'm creating a tiddler with team member details and have a macro I can call whose purpose it is to filter that list by a tiddler field. 

\define my-contacts(team role)
  <table>
    <th>ROLE</th>
    <th>NAME</th>
    <th>TEAM</th>
    <th>LOCATION</th>
      <$list filter="[tag[person]team[$team$]role[$role$]sort[role]]" template="$:/core/ui/ListItemTemplateContacts"/>
  </table>

\end

The filtering issue occurs when I have team members who can have the title 'Android Developer' or 'iOS Lead Developer'. 

How can I use regex and the macro variable `role` (given I'm passing the value `Developer`) to match any contact with `Developer` in their role title? Regex isn't a requirement. Just the first option that came to mind. 

Stephan Hradek

unread,
Sep 10, 2019, 8:57:09 AM9/10/19
to TiddlyWiki
Not sure whether I completely understand, but try:

      <$list filter="[tag[person]team[$team$]regexp:role[$role$]sort[role]]" template="$:/core/ui/ListItemTemplateContacts"/>


Christian Macedo

unread,
Sep 10, 2019, 9:02:46 AM9/10/19
to TiddlyWiki
I got it. 

I had to add a set

\define my-contacts(team role)
 
<table>
   
<th>ROLE</th>
    <th>NAME</
th>
   
<th>TEAM</th>
    <th>LOCATION</
th>

   
<$set name="role-pattern" value=$role$>
     
<$list filter="[tag[person]team[$team$]regexp:role<role-pattern>sort[role]]" template="$:/core/ui/ListItemTemplateContacts"/>
   
</$set>
 
</table>


\end
Reply all
Reply to author
Forward
0 new messages