Trim [[ or trim ]] not working

76 views
Skip to first unread message

Sheridan Price

unread,
Dec 17, 2021, 10:54:00 AM12/17/21
to TiddlyWiki
Hello 
I am new to TW so I won't be surprised if the answer is obvious in retrospect.
I have:

<$vars prefix="[[" suffix=" ]]">
<$list filter="[[smpConfig]get[animals]trim:prefix[<prefix>]]"/>
</$vars>

If I don't have the trim part then the output is: [[Fox ]] [[Beaver ]]...  all good but once the trim is added there is no output.

So what silly error am I making?

The intent behind this is as part of a larger activity (naturally) that will take the resulting list of animals and find all tiddlers that have a field with that animal name. A tiddler could have none, some or all of the animal names as fields. I believe I can figure out the rest or at least have fun trying but this trim problem has me beat. I have checked the documentation, google searching and here to no avail. Help as they say

Regards 
Sher


Mat

unread,
Dec 17, 2021, 11:21:32 AM12/17/21
to TiddlyWiki
I didn't try out your code but it looks like a simple syntax error. Try:

... trim:prefix<prefix>]"/>

<:-)

Eric Shulman

unread,
Dec 17, 2021, 11:29:51 AM12/17/21
to TiddlyWiki
On Friday, December 17, 2021 at 7:54:00 AM UTC-8 sheri...@gmail.com wrote:
``` 
<$vars prefix="[[" suffix=" ]]">
<$list filter="[[smpConfig]get[animals]trim:prefix[<prefix>]]"/>
</$vars>
```
If I don't have the trim part then the output is: [[Fox ]] [[Beaver ]]...  all good but once the trim is added there is no output.
So what silly error am I making?

A couple of things:
1) The brackets surrounding a filter operand are actually part of the operand itself, and indicate the kind of operand to process:
  * square brackets enclose literal values
  * angle brackets enclose variable references
  * curly braces enclose tiddler references

Thus, you want to write: `trim:prefix<prefix>` instead of `trim:prefix[<prefix>]`

2) The `get[foo]` syntax returns the value in the field named "foo" **as a single block of text**.  To handle the retrieved value as a space-separated, bracketed list of items, you should use the `enlist-input[]` filter operator, like this:

`<$list filter="[[smpConfig]get[animals]enlist-input[]"/>`

3) Your example list, retrieved from the field named "animals", seems to include trailing space for each animal name.  I suggest omitting the extra spaces in the field content.  Alternatively, you can use `trim:suffix[ ]` in your filter, like this:

`<$list filter="[[smpConfig]get[animals]enlist-input[]trim:suffix[ ]]"/>`

enjoy,
-e

Sheridan Price

unread,
Dec 18, 2021, 10:17:25 AM12/18/21
to TiddlyWiki
I hope I did this reply correctly (I used reply all).

So I tried it out and for the sake of anyone else who might read this in the future here goes.

Trim works if written as   trim:prefix<prefix>  Thanks to both Eric and Matt for their response. 

As Eric mentions as given in the original post the filter will produce a single block of text that the trim sees as a single "word" to trim so only the leading [[ is  removed for trim prefix and the very last ]] is removed for the  trim suffix. If the enlist-input[] is included then the filter works as desired outputting a list of just the animal names with no brackets [[ ]] at all to be seen surrounding them. Thanks Eric for that. Also thank you for the explanation on bracketing in filter expressions. I knew of it but hadn't integrated it properly into my brain. This problem and your explicit mention of those syntaxes has now done that.

Thank you both
Regards
Sher
Reply all
Reply to author
Forward
0 new messages