Filter a list with a variable that contains multiple words

566 views
Skip to first unread message

Fidel N

unread,
Nov 12, 2016, 2:04:05 PM11/12/16
to TiddlyWiki
Hey guys, the following code only works when "myVar" contains one word.
Whenever two words come out of it, the filter doesnt work properly, despite I confirmed the variable contains the two words it should (by trying it using <<myVar>> and checking that it has)
Here is the filter I'm refering to, specifically, the "remove" order:

<$set name="myVar" value=<<currentTiddler>>>
<$list filter='[is[current]tags[]remove
<myVar>]'></$list>
</$set>

How should I write myVar within the filter for it to work also when it's value contains two words?

Thanks!!

Mark S.

unread,
Nov 12, 2016, 3:12:19 PM11/12/16
to TiddlyWiki
There's no documentation explaining what the filter wants in terms of and "array". But this variation seems to work:

<$set name="myVar" value=<<currentTiddler>
>>

<$list filter='[is[current]tags[]] -[
<myVar>]'></$list>
</$set>


Be sure to switch the tiddler out of edit mode -- this won't work in preview mode (because the underlying title will be "Draft of my tiddler".)

I'm not sure why you would want to run this, since it means you have a tiddler tagged with it's own name.

HTH
Mark

Fidel N

unread,
Nov 12, 2016, 3:56:03 PM11/12/16
to TiddlyWiki
Yes, the way I use it is, in the default tiddler that appears whenever you create a new tag (with that tags name), i put this, so whenever I open a tag's main tiddler, I see all the tiddlers with that tag, see their other tags, but don't see the main tag all the time (hence the removing of that specific one).

Here is the code in case its useful to someone else:

<$list filter="[tags[]!is[system]]">{{||$:/core/ui/TagTemplate}}

<$set name="myVar" value=<
<currentTiddler>>>
<$list filter='[is[current]tags[]]'>{{||$:/core/ui/TagTemplate}}</$list>
<ul>
<$list filter="[tag
<currentTiddler>]">
<li><$list filter='[is[current]tags[]] -[<myVar>]'>{{||$:/core/ui/TagTemplate}}</$list><$link>{{!!title}}</$link></li>

</$list>
</ul></$set>
</$list>


Still, I would like how to do that using a filter, just in case in the future I need to use a filter operation with a variable that contains more than 1 word...

Thank you very much for your answer though, It totally solves the problem :)

Fidel N

unread,
Nov 15, 2016, 3:13:37 AM11/15/16
to TiddlyWiki
The code in the previous post did it for ALL the tiddlers within the current TW.
For completeness, this is the code that does it just for the current tiddler tittle:

<currentTiddler>{{||$:/core/ui/TagTemplate}}
<br/>

<$set name="myVar" value=<
<currentTiddler>
>>

<$list filter="[tag
<currentTiddler>!is[system]]">
<ul>
<$list filter="[is[current]!is[system]tags[]] -[
<myVar>]">
{{||$:/core/ui/TagTemplate}}
</$list>

<$link><
<currentTiddler>><$link/>
<br/>

Best regards!

Jed Carty

unread,
Nov 15, 2016, 3:18:36 AM11/15/16
to TiddlyWiki
You can also get around this by using a list widget instead of set:

<$list variable="myVar" filter=<<currentTiddler>>>

<$list filter='[is[current]tags[]remove
<myVar>]'></$list>
</$list>


Fidel N

unread,
Nov 15, 2016, 3:44:23 AM11/15/16
to TiddlyWiki
Thanks Jed, thats precisely what I reported in the first post in this thread, and I would like that solution since I find it more elegant and stable, but I found out it doesnt work (and just re-confirmed) when its trying to remove a value that has spaces in it ( the value of myVar contains more than 1 word).
When its just one word it works great though. Is there any walk around that problem?

Jed Carty

unread,
Nov 15, 2016, 3:57:46 AM11/15/16
to TiddlyWiki
Oh, sorry I wasn't paying attention when I copied from your post instead of from what I made on tiddlywiki.com, this should work:

<$list variable="myVar" filter='[
<currentTiddler>]'>
<$list filter='[is[current]tags[]]-[
<myVar>]'></$list>
</$list>

I am not sure what situation this is useful in, but to test it I put this code in the tiddlery Working with TiddlyWiki on tiddlywiki.com and gave that tiddler the tag 'Working with TiddlyWiki' as well as the tags 'Working' 'with' and 'TiddlyWiki' and it listed 'TableOfContents' 'Working' 'with' and 'TiddlyWiki'

Hopefully this is the behaviour you want. If not let me know.

Fidel N

unread,
Nov 16, 2016, 6:59:28 AM11/16/16
to TiddlyWiki
Thanks Jed. Yes, that is very close to the option Mark S. pointed out in his first answer to this thread, and the solution I began using.
The problem is solved and now TW does what I wanted, but what still is missing is the correct way to use filters with variables that contain multiple words, since, IMO, "
remove<myVar>" should work as a filter.

Thanks for taking the time to check the thread! :)

Jed Carty

unread,
Nov 16, 2016, 7:25:35 AM11/16/16
to TiddlyWiki
This is a very annoying property of the set widget that I am unhappy with that a lot of the operators added with action-listops also use. The problem is that the set widget returns each word as a separate list item and doesn't handle titles with spaces in a way that plays well with other things. I thought in this context the list widget fixed the problem but the remove operator has the same thing where it will only take a multi-word input as a single item if it has [[ and ]] around it.

One way to use the remove operator like you want is like this:

<$set name="myVar" filter='[<currentTiddler>]'>

<$list filter='[is[current]tags[]remove
<myVar>]'></$list>
</$set>

I will be quiet now since I think you have a solution and this is just be me complaining :p

Fidel N

unread,
Nov 17, 2016, 3:27:17 AM11/17/16
to TiddlyWiki
Any opportunity is good to learn about TW internals, thanks for the explanation and the replacement code it was very useful to me, and allows for the use of operators with multiple words.
Then again, shoudlnt that be in the main documentation of operators? So people can use them with multi-word variables?

Mike Andyl

unread,
Jul 8, 2021, 5:36:55 AM7/8/21
to TiddlyWiki
I'm trying to figure out how it works, simplified the example, and it doesn't do anything. Does it not fit in newer versions?

<$set name="myVar" filter='[tags[About]]'>
<$list filter='<myVar>'></$list>
</$set>


четверг, 17 ноября 2016 г. в 11:27:17 UTC+3, fidel...@gmail.com:

Eric Shulman

unread,
Jul 8, 2021, 6:37:00 AM7/8/21
to TiddlyWiki
On Thursday, July 8, 2021 at 2:36:55 AM UTC-7 miket...@gmail.com wrote:
I'm trying to figure out how it works, simplified the example, and it doesn't do anything. Does it not fit in newer versions?
<$set name="myVar" filter='[tags[About]]'>
<$list filter='<myVar>'></$list>
</$set>


* The [tags[]] filter operator doesn't accept a operand value.  You want to use [tag[About]] to match tiddlers with the "About" tag.
* When using a variable as a parameter value (in the $list widget),  do not enclose it in quotes, and use doubled angle brackets
* The $list widget needs some syntax inside it to indicate what to output

Here's a corrected version of your example code:
<$set name="myVar" filter="[tag[About]]">
<$list filter=<<myVar>>><$link/><br></$list>
</$set>

-e

Mat

unread,
Jul 8, 2021, 9:54:33 AM7/8/21
to TiddlyWiki
yeah, Eric is right. A small addition is that filters should generally be enclosed in triple quotes because if any of the filtered out items has quotes in it, then this can conflict with the enclosing filter quotes. So, get into the habit of writing filter="""..."""

To see the problem, you can test to create a new tiddler titled  This is a "new" tiddler  and tag it with  About

<:-)

TW Tones

unread,
Jul 11, 2021, 12:25:47 AM7/11/21
to TiddlyWiki
Mat,

That is a good point, I will just add the alternative is to not use double quotes in any tiddler title, only use single quotes then "value" "filter" is sufficient.

Without going into the details now, we can use Unicode characters that look like quotes as well, but do not delimit like them eg “ 

Regards
Tones

Reply all
Reply to author
Forward
0 new messages