A simple filter - can not get it to work

I am trying to understand filter syntax and processing by trying out a simple filter, at least I think it should be simple filter.

_canonical_uri={{{ [{$:/TLS/incremental}addprefix[Images/CS]addsuffix[.]addsuffix[$:/TLS/storage_format]] }}}

This is being used as a parameter to a create_tiddler action.

What I am trying to achieve is to set the _canonical_uri field of a tiddler to ‘Images/CS’ + the value of the tiddler $:/TLS/incremental + ‘.’ + the contents of th e tiddler $:/TLS/storage_format

When I type this filter into the filter tester of the advanced search tab, it returns

_canonical_uri= Images/CS15.$:/TLS/storage_format

No matter what I try, I can not get the content of the $:/TLS/storage_format tiddler whilst it should return, in this case, pdf. So the hoped for result is _canonical_uri= Images/CS15.pdf

If I replace the last addsuffix by addsuffix[pdf] everything works a treat so the issue would not appear to be the filter syntax.

I can not find any examples showing how to do this.

All help appreciated especially if you can point to a tiddler in the documentation where this type of statement id explained.

bobj

In filter syntax, the brackets surrounding a filter operand indicate how that filter operand is interpreted:

  • square brackets surround literal text value
  • curly braces surround tiddler references
  • angle brackets surround variable names or macros

Thus, in your filter, addsuffix[$:/TLS/storage_format] is incorrect.
You should use addsuffix{$:/TLS/storage_format} instead.

Note also that another way to write the entire filter is:

_canonical_uri={{{ [[Images/CS]] [{$:/TLS/incremental}] [[.]] [{$:/TLS/storage_format}] +[join[]] }}}

i.e., specify the literal and tiddler references as separate filter runs which are then joined together to form the complete string.

enjoy,
-e

1 Like

@EricShulman thanks for that explanation. Will add it to my slowly increasing examples TW

Could your answer, which works a treat, not be included in the TW documentation page on Brackets (https://tiddlywiki.com/#Brackets)? Might make things more clear for us novices.

bobj

There is a important point when you are using filter, you need to use the filter syntax. You can’t use brackets as you do in WikiText, as @EricShulman has pointed. I think this documentation could be of help, because you can see how could use filter parameter/operand according to you needs.