Adding duplicate title in title list

32 views
Skip to first unread message

andres....@gmail.com

unread,
Feb 16, 2022, 5:17:51 PM2/16/22
to TiddlyWiki
Ok, so I have the following list:

    foo foo foo bar

I then want to append 'foo' to the end of that list such that I wind up with:

    foo foo foo bar foo

So I try the following filter:

    [[foo foo foo bar]enlist-input:raw[]] [[foo]]

That results in:

    foo foo bar foo

This is unexpected to me, which means that there is something I don't understand.

So I have two questions:

1. Why is the title not appended as I expected?
2. How can I get the result I want? To add complexity (cause why not?), the list will be generated dynamically based on user input, titles will only sometimes be of existing tiddlers, and the titles can have spaces xD.

andres....@gmail.com

unread,
Feb 16, 2022, 5:29:28 PM2/16/22
to TiddlyWiki
I should add that the list is currently stored as a field, so my filter is more along the lines of
[all[current]get[fieldName]enlist-input:raw[]] [<addedTitle>]

I couldn't use the listops action widget subfilters because they automatically dedup so I need to use the full filter which doesn't fully dedup my list but, at least with this filter, still makes me lose entries.

Eric Shulman

unread,
Feb 16, 2022, 5:43:56 PM2/16/22
to TiddlyWiki
Answer to question #1:

By default, titles resulting from a filter are only listed once, with the last instance of a given title "dominantly appended" to the list (i.e., duplicates are removed).  Thus, in your example, adding `[[foo]]` to the end of the list automatically removed the first instance of `foo` from the front of the list.  You've already discovered the use of the `:raw` suffix for the `enlist-input` operator, which prevents duplicates from being removed when you enlist an existing space-separated list.  Another bit of filter syntax that helps with preserving duplicates is the "=" prefix on a filter run.  To get the results you expected, you would write: `[[foo foo foo bar]enlist-input:raw[]] =[[foo]]`.

Answer to question #2:

As you noted in your followup message, you have an existing list stored in a tiddler field called `fieldName`.  Let's assume this field contains 4 items: `foo [[bar baz]] mumble [[frotz gronk snork]]` (where the 2nd and 4th items contain spaces).  To add an item to that list, you would write something like this:: `[<currentTiddler>get[fieldName]enlist-input:raw[]] =[<addedTitle>]`.  Note also that using `<currentTiddler>` in your filter is *slightly* more efficient than `all[current]`, since the `all[]` operator first needs to parse the operand (`current`) to determine that you want to retrieve the current tiddler's title, while `<currentTiddler>` directly retrieves the title without the added internal layer of parsing.

enjoy,
-e

andres....@gmail.com

unread,
Feb 16, 2022, 8:34:01 PM2/16/22
to TiddlyWiki
Amazing response, Eric. Thank you!

That worked perfectly! I need to spend some quality time with https://tiddlywiki.com/#Filter%20Expression. There is a lot of new stuff on there I hadn't seen before!

> Note also that using `<currentTiddler>` in your filter is *slightly* more efficient than `all[current]`
See, I used to use currentTiddler but saw so many examples with all[current] that I assumed that there was some optimization going on there. Noted and adjusted. Great tip!

> enjoy
I will, thank you!
Reply all
Reply to author
Forward
0 new messages