removeprefix

223 views
Skip to first unread message

tobaisch

unread,
Jan 2, 2018, 12:31:17 PM1/2/18
to TiddlyWiki
Hello,
all my tiddlers have a number in the title as a prefix.
"0001-ABC" to "1000-EGAL".
I already have the prefix 0001-1000 exactly as a field:"nr".
I would like to show all Tiddler without this previx in a list and sort after the first letter

Actually, one would only have to remove the field: "nr" from the beginning of the title
Or do I understand something wrong?
I have found here in the forum 2 variants but they do not work.
    <<list-links "[all[tiddlers]removeprefix[field:nr]] !prefix[field:nr]">>
    or
    [removeprefix[field:nr] [!prefix[field:nr]]

Thanks
Regards
Tob

Mark S.

unread,
Jan 2, 2018, 1:12:29 PM1/2/18
to TiddlyWiki
I think you'll need nested lists:

<$list filter="[all[tiddlers]has[nr]]">
<$vars nr={{!!nr}}>
<$list filter="[all[current]removeprefix
<nr>]">
<$view field="title"/>
<br/>
</$list>
</$vars>
</$list>

The problem is that your final list won't necessarily be sorted the way you expect.

Good luck,
Mark

tobaisch

unread,
Jan 2, 2018, 2:31:11 PM1/2/18
to tiddl...@googlegroups.com
Thanks Mark,

The problem is that your final list won't necessarily be sorted the way you expect.

This is really a big problem.
That's the reason why I wanted this list in this form.
Also, I can not use it as a template.
I wanted to use this as a template for the search.
Is your assessment final or do you think that there may be another solution?
That does not sound good. :(

Maybe you can improve something in my initially mentioned variants, that they work?
Why
<$list filter="[all[tiddlers]nsort[]] +[removeprefix[{{!!nr}}]]" />
does not work?
Regards
Tob

Diego Mesa

unread,
Jan 2, 2018, 2:47:43 PM1/2/18
to TiddlyWiki
Hello Tob,

I frequently use Tobias' excellent split plugin.

You could use:

[all[tiddlers]has[nr]split:after[-]sort[]]

to get the correct list of sorted "titles". The thing is you'd now have to link them to the correct tiddler. 


On Tuesday, January 2, 2018 at 2:31:11 PM UTC-5, tobaisch wrote:
Thanks Mark,
The problem is that your final list won't necessarily be sorted the way you expect.
This is really a big problem.
That's the reason why I wanted this list in this form.
Also, I can not use it as a template.
I wanted to use this as a template for the search.
Is your assessment final or do you think that there may be another solution?
That does not sound good.
:(
Regards
Tob

Diego Mesa

unread,
Jan 2, 2018, 3:15:19 PM1/2/18
to TiddlyWiki
A quick example: 

With the following tiddlers:
  • 001-ABC
  • 002-BCD
  • 003-AAA
where they have the appropriate nr fields, you can use:

<$list filter="[all[tiddlers]has[nr]split:after[-]sort[]]" variable="asd">
    <$list filter="[all[tiddlers]suffix
<asd>]">
        <$view field="title"/>
<br/>
    </$list>
</$list>

My missing link to Tobias split plugin: https://tobibeer.github.io/tw5-plugins/#split

tobaisch

unread,
Jan 2, 2018, 5:24:01 PM1/2/18
to tiddl...@googlegroups.com
    Many Thanks.
    The plugin looks like a solution but so far I have not had any success.
    Short to your variant:
    I have no "-" therefore it does not fit.
    And also your list is not displayed as a link. This is exorbitantly important, because I want to call the found Tiddler.
    Ex: My Tiddler title: 0299 lastname prename - something
    I have the plugin installed.
    My experiments and many others brought nothing:

    <$list filter="[all[tiddlers]has[nr]nsort[]]split:after[pos=4]"/>
    <$list filter="[all[tiddlers]has[nr]split[pos=5 num=1]nsort[]]"
/>
   
Although there are many examples on this site, my case was not listed as an example :(
    And it also makes it seem as if the links do not work anymore after splitting, which in turn is out of the question as a solution for me.
    That's why I like to stay with the old version and want to find the mistake here.

      
 <$list filter="[all[tiddlers]nsort[]] +[removeprefix[{{!!nr}}]]" />

    Thank you again, thank you all for your effort.
    You are really friendly and helpful here!
Regards
Tob
 

Mark S.

unread,
Jan 2, 2018, 5:54:23 PM1/2/18
to TiddlyWiki
The problem is that you're attempting to use the title field in 2 additional ways, in addition to it being a title and an ID field. This creates all sorts of headaches.

Anyway, the solution is to make a button that will populate a field with the suffix. Then you can easily list and sort by that field while creating links to the original tiddler title.

-- Mark

tobaisch

unread,
Jan 2, 2018, 6:30:30 PM1/2/18
to tiddl...@googlegroups.com

hello Mark,
thanks, at the beginning I just wanted to ensure a reasonably structured presentation of my Tiddler.
The field "nr" I have just set up for security to filter later thereafter.

Unfortunately that does not seem to work right now.
I do not understand what should be so annoying now about these numbers?
The structure is always the same. I can delete the field "nr", but does that help?
I can also delete the number from the title.
But does that really make sense? A reversal is more difficult.
The number is an very important part of each Tiddler.
It gives me a lot of important information about the content via numeric code.
I use the number also with the direct search input.
The contents of the fields are not found with the standard search.

I would then have to change the default display for the Tiiddler and insert the content of the field "nr" as a prefix.
And in addition I have to insert the number as text content so that the tiddler can also be found in the standard search.
Also, there are many tiddler with exactly the same title. I would have to come up with a separate distinction, for example with a sufix (variant, variant 2 ..).
Actually everything speaks against a removal of the number.
Maybe that would be a solution?
But why so complicated?
I still hope for a simpler solution.

Don't forget, i will make a template to change the display of my searchresults.
A static list ist not what im looking for i m looking for a filteroption.
What is the mistake in this type of code?


 <$list filter="[all[tiddlers]nsort[]] +[removeprefix[{{!!nr}}]]" />

Regards
Tob

Eric Shulman

unread,
Jan 2, 2018, 8:13:59 PM1/2/18
to TiddlyWiki
On Tuesday, January 2, 2018 at 3:30:30 PM UTC-8, tobaisch wrote:
What is the mistake in this type of code?

 <$list filter="[all[tiddlers]nsort[]] +[removeprefix[{{!!nr}}]]" />

Two problems:
1) the brackets on the "removeprefix" filter are wrong.  When referencing a field value, just use SINGLE curly braces, like this:

+[removeprefix{!!nr}]

2) I assume your intention is to remove the number prefix from each tiddler title, based on the "nr" field of each tiddler.  However, the "current tiddler" context for your filter is the tiddler that *contains* the <$list> widget, rather than the title of each tiddler found in the first part of the filter.  To do as you want, you need to nest two filters, like this:

<$list filter="[all[tiddlers]nsort[]]">
   <$list filter="[all[current]removeprefix{!!nr}}">
   ...
   </$list>
</$list>

-e


tobaisch

unread,
Jan 2, 2018, 9:40:27 PM1/2/18
to TiddlyWiki
Hello Eric,
thanks.
Your assumption is correct.
Your code does not work for me.
Also no error message
Is there something else to be added instead of the "..."?
Regards
Tob

Eric Shulman

unread,
Jan 3, 2018, 12:07:57 AM1/3/18
to tiddl...@googlegroups.com
My apologies... I'm usually MUCH more verbose in my responses.  Let me try again:

Using this code:
<$list filter="[all[tiddlers]nsort[]]">
   <$list filter="[all[current]removeprefix{!!nr}]">
   ...
   </$list>
</$list>
 
The outer $list widget iterates over all the tiddlers in the document, sorted numerically.  By default, as it iterates, it sets the value of the "currentTiddler" variable, so that within the outer $list, the "currentTiddler" is equal to each tiddler title it finds, one at a time.

The inner $list widget then operates on the current tiddler title, using filter syntax "all[current]", and removes the prefix (if any), based on the value of the "nr" field of the current tiddler.

Here's where I left out some explanation (and some important syntax too!)...

Within the body of the inner $list widget, the value of currentTiddler should then be a tiddler title with the number prefix removed.  However, there's TWO issues here that I failed to touch on:

1) If there is NO "nr" field in the current tiddler, then the "removeprefix" filter will return the current tiddler title, unchanged.  This would cause matches with tiddlers that are unnumbered.  To exclude those tiddlers and only show tiddlers that actually have an nr value defined, we need to test that the "nr" field is actually present in that tiddler, by using the has[fieldname] filter operator, like this:

   <$list filter="[all[current]has[nr]removeprefix{!!nr}]">

2) I used "..." as a placeholder for "... and then you do more stuff with the matched tiddler..."  Let's assume that "more stuff" is something like "output a link to the matched tiddler".  To do this, you want to preserve access to the FULL name of the tiddler, *including* the number, so you can link to it.  But you also want the truncated tiddler title *without* the number for display purposes.  To do this, you can add a separate "variable" param to the <$list> widget, like this:

   <$list filter="[all[current]has[nr]removeprefix{!!nr}]" variable="thisTiddler">

This will avoid changing the value of "currentTiddler" as set by the outer $list widget, and instead using "thisTiddler" to store the title with the prefix removed.  You can then construct a suitable $link widget output within the inner $list widget, using both variables accordingly... like this:

<$list filter="[all[tiddlers]nsort[]]">
   <$list filter="[all[current]removeprefix{!!nr}]" variable="thisTiddler">
     
<li> <$link to=<<currentTiddler>>> <$text text=<<thisTiddler>>/> </$link> </li>
   </$list>
</$list>

Notes:
a) The <li>...</li> syntax makes the output show as a bullet point
b) The $link widget uses the value of "currentTiddler" by default, so it could be written as just <$link>...</$link> without the to="..." param and it would still work as intended
c) The $text widget ensures that the text is displayed without additional processing for automatic WikiWord linking (e.g., if the tiddler title is "0123 SomeThing", then the "SomeThing" text won't become a link to a "SomeThing" tiddler, but WILL be linked to the full "0123 SomeThing" title, based on the containing $link widget.

I hope this explanation doesn't confuse you more!

let me know how it goes...
-e

tobaisch

unread,
Jan 3, 2018, 2:32:16 AM1/3/18
to tiddl...@googlegroups.com
U-N-B-E-L-I-E-V-A-B-L-E
thank you so much.
It works as it should.
And I can also use it as a template.
But the sorting does not work anymore.
It sorted according to the numbers like before, but should now sort by the first letters.
I tried to put the nsort[]
at all sorts of position after removeprefix but had no success.
Hmm?
Regards
Tob.

Mark S.

unread,
Jan 3, 2018, 10:00:48 AM1/3/18
to TiddlyWiki
All the sorting occurs in the outer loop. But there's no mechanism to sort by a portion of the title.

Putting multiple pieces of information into a single field (the title) causes headaches.

This is why I suggested creating a field to sort by in each tiddler.

-- Mark

tobaisch

unread,
Jan 3, 2018, 10:58:39 AM1/3/18
to tiddl...@googlegroups.com
What about a sorting from position n?
So I sort before the removal of the numbers
Today we can make livestreams with any smartphone to the ISS and cars they driving alone but no sorting of letters in a list! :)
Regards
Tob

Mark S.

unread,
Jan 3, 2018, 12:11:14 PM1/3/18
to TiddlyWiki
There is no "sort from position N" filter. Perhaps you could make a Pull Request for one.

It's possible that someone has made a 3rd party tool for this.

Use separate fields for the parts of the title and your problems will disappear.

You can't watch TV on your 2018 multi-cooker, nor send a message to the ISS via paper airplane. All technology has limits of some sort.

-- Mark

tobaisch

unread,
Jan 3, 2018, 1:55:06 PM1/3/18
to TiddlyWiki

All the sorting occurs in the outer loop. But there's no mechanism to sort by a portion of the title.

Are you 100% sure that there is no possibility for sorting after removeprefix?
I can remove the numbers from the title, but undoing them will be very difficult.
I have already a field "nr" with the numbers.

Is there another field beside the title field which is (or can be make) searchable with the standard search?
Regards
Tob

coda coder

unread,
Jan 3, 2018, 2:37:52 PM1/3/18
to TiddlyWiki
Try this (untested)

<$list filter="[all[current]has[nr]removeprefix{!!nr}sort[]addprefix{!!nr}]">

   <$list filter="[all[current]removeprefix{!!nr}]" variable="thisTiddler">
     
<li> <$link to=<<currentTiddler>>> <$text text=<<thisTiddler>>/> </$link> </li>
   </$list>

</$list>

Mark S.

unread,
Jan 3, 2018, 2:41:39 PM1/3/18
to TiddlyWiki
The nr number contains the prefix, right? But you want to sort by the suffix?

So add a field that also contains the suffix (perhaps sfx).

You don't have to change the title. You can then sort by the sfx field and display it but link to the title field.

The list code might look like:

<$list filter="[has[sfx]sort[sfx]]">
<$link><$view field=sfx/></$link><br/>
</$list>

-- Mark

Mark S.

unread,
Jan 3, 2018, 2:49:55 PM1/3/18
to TiddlyWiki
That won't work because it will only remove the prefix stored in the nr field of the calling tiddler.

It only takes a couple of tiddlers to test. Attached.

-- Mark
tiddlers(3).json

tobaisch

unread,
Jan 3, 2018, 5:19:03 PM1/3/18
to tiddl...@googlegroups.com
hello coda coder,
thanks, but it doesnt work too.

@Mark
 
So add a field that also contains the suffix

Is not that a waste of data? I then have twice the suffix once in the title and once in the field. With 800 Tiddlers that makes a difference.
I rather thought of deleting the prefix (this is faster in Notepad ++) and then adding the field "nr" in the view of the standard search.
I have to think through all variants again.
And maybe even a clever head will come around here and find a solution?
David Copperfield's, Sergey Brin's
where are you?
Mark, w
hat do you say to my questions?
Are you 100% sure that there is no possibility for sorting after removeprefix?
Is there another field beside the title field which is (or can be make) searchable with the standard search?
Thanks
Regards
Tob




Mark S.

unread,
Jan 3, 2018, 5:25:27 PM1/3/18
to TiddlyWiki
For 800 tiddlers it would add about 8k. Which compared to the baseline 2.5 meg size of TW5 is little.


On Wednesday, January 3, 2018 at 2:19:03 PM UTC-8, tobaisch wrote:
hello coda coder,
thanks, but it doesnt work too.

@Mark
 
So add a field that also contains the suffix

Is not that a waste of data? I then have twice the suffix once in the title and once in the field. With 800 Tiddlers that makes a difference.
I rather thought of deleting the prefix (this is faster in Notepad ++) and then adding the field "nr" in the view of the standard search.
I have to think through all variants again.
And maybe even a clever head will come around here and find a solution?
Mark, what do you say to my questions?

Mark S.

unread,
Jan 3, 2018, 5:37:40 PM1/3/18
to TiddlyWiki
PS: Here's the code to help make all those sfx fields. Be sure to make a back-up first in case I've made a mistake or your data is different somehow:

<$button>Create suffix field
<$list filter="[has[nr]]">
<$list filter="[all[current]removeprefix{!!nr}]" variable="sfx">
<$action-setfield  sfx=<
<sfx>>/>
</$list>
</$list>
</$button>

-- Mark

tobaisch

unread,
Jan 3, 2018, 5:58:33 PM1/3/18
to TiddlyWiki
This is a really cool button.
Thanks a lot!

 
Reply all
Reply to author
Forward
0 new messages