Is it possible to escape characters in filter?

I want a filter to return a string that would contain the sort syntax of a filter. A button (of a table column) that toggles the sort order for that field (toggles between ascending and descending order).

I’d like one filter, something like this:

[[$:/state/sortcolumn]get<currentTiddler>match[XXXXX]then[YYYYY]else[XXXXX]]

where XXXXX would something like [sort[date]] and YYYYY would be [!sort[date]

but how does one escape these extra brackets?

Thanks

As you’ve noted, you can’t directly use square brackets as a literal text filter parameter value (because the filter syntax itself uses square brackets as delimiters that enclose the parameter value).

Unfortunately, there is no easy “escape” syntax that allows you to use square brackets the way you’d like. However, you can work around this syntax limitation by putting the desired text into variables, and then reference those variables within the filter syntax, like this:

<$let XXXXX="[sort[date]]" YYYYY="[!sort[date]]"
  result={{{ [[$:/state/sortcolumn]get<currentTiddler>match<XXXXX>then<YYYYY>else<XXXXX>] }}}>

enjoy,
-e

@EricShulman Thank you, I’ll give that a try.

I also had this wild idea of trying HTML character codes–but I suspect that would not work either.

@EricShulman I should have worked this out for myself. Thank you. With the use of templates, I can provide various types of lists, including tables with pagination. This little bit enabled the table to be sortable by column, supporting both ascending and descending. Now, I need to add an icon to the column to show direction: