Struggling with a set command

I have this command (variable pp represents parentplace):

<$set name=trclass filter="[is[current]contains:place<pp>then[]else[highlight-row]]">

This is setting a variable named trclass (as in a table row class name. This commands works. However, I also want it to work if variable “pp” is not defined. So, my rules are:

if pp is not defined: trclass should be blank/empty string.
if pp is defined and contains in place field of the current tiddler then return blank/empty string.
if pp is defined and not contains in place field of the current tiddler then return “highlight-row”.

CoPilot came up with this:

<$set name=trclass
      filter="[<pp>match[]then[]else[
                 [is[current]contains:place<pp>]
                 [is[current]!contains:place<pp>then[highlight-row]else[]]
              ]]">

…which I have not been able to get to work.

Thanks, any help would appreciated.

Craig

The Copilot code doesn’t work because it’s trying to use entire filter runs as the parameter of a filter operator, which isn’t valid filter syntax.

I’d try something like this instead:

filter="[<pp>!match[]] :map[<..currentTiddler>!contains:place<pp>then[highlight-row]]"

If you filter for the one instance in which you want a non-blank result (i.e. <<pp>> is non-blank and !!place does not contain <<pp>>) you shouldn’t have to specify a fallback else[], as all other cases will produce an empty result by default.

1 Like

@etardiff Thank you. This is about the 5th time the correct solution was with the use of :map.for complex filters.

1 Like

This should also work (without using :map)…

filter="[<pp>!match[]then<currentTiddler>!contains:place<pp>then[highlight-row]]"

-e