From Fields in certain tiddlers, Creating comma list for use in URL

39 views
Skip to first unread message

David

unread,
Jun 29, 2020, 12:56:19 PM6/29/20
to TiddlyWiki
I'm dealing with tracking numbers lately.  I have several tiddlers that represent incoming shipments.  they have "tracking_number" field in each of them.

There's a site called 17track that is great for tracking multiple shipments at once.  Its urls look like this:


So I want to create a Link in my "master" tiddler (that shows all the incoming shipments) that has a concatenated comma list of all the tracking numbers for the shipments.


This code will give me a comma-list that is correct, but it is just rendered into the view and not available as a variable.  But maybe it can be put into a link somehow.

<$list filter="[tag[IncomingItem]!has[date_received]has[tracking_number]]">{{!!tracking_number}},</$list>


This code almost gets me there, but it renders the list of trackin numbers as space-delimited instead of comma.  I wasn't able to find a way to find/replace.

<$set name="myVariable" filter="[tag[IncomingItem]!has[date_received]has[tracking_number]get[tracking_number]]">
<a href={{{[
<myVariable>addprefix[https://t.17track.net/en#nums=]]}}} >Track All</a>
</$set>


You guys have been so much help today!

Maybe I'm trying to make it do something TW is not supposed to be able to do easily.  And I'm sure open to learning some other technique to do the above if it is better code for TW.

Thank you!

Eric Shulman

unread,
Jun 29, 2020, 1:20:16 PM6/29/20
to TiddlyWiki
On Monday, June 29, 2020 at 9:56:19 AM UTC-7, David wrote:
This code almost gets me there, but it renders the list of trackin numbers as space-delimited instead of comma.  I wasn't able to find a way to find/replace.
<$set name="myVariable" filter="[tag[IncomingItem]!has[date_received]has[tracking_number]get[tracking_number]]">
<a href={{{[
<myVariable>addprefix[https://t.17track.net/en#nums=]]}}} >Track All</a>
</$set>

This one is easy!  Add "join[,]" to the end of your filter, like this:

<$set name="myVariable" filter="[tag[IncomingItem]!has[date_received]has[tracking_number]get[tracking_number]join[,]]">
<a href={{{[
<myVariable>addprefix[https://t.17track.net/en#nums=]]}}} >Track All</a>
</$set>

note: you don't actually need to use a variable at all.  Just combine the two filters, like this:
<a href={{{[tag[IncomingItem]!has[date_received]has[tracking_number]get[tracking_number]join[,]addprefix[https://t.17track.net/en#nums=]]}}} >Track All</a>

also, you might want to add target="_blank" to your link, so that it opens in a separate tab/window.
<a target="_blank" href={{{[tag[IncomingItem]!has[date_received]has[tracking_number]get[tracking_number]join[,]addprefix[https://t.17track.net/en#nums=]]}}} >Track All</a>

enjoy,
-e


Eric Shulman

unread,
Jun 29, 2020, 1:31:32 PM6/29/20
to TiddlyWiki
On Monday, June 29, 2020 at 10:20:16 AM UTC-7, Eric Shulman wrote:
<a target="_blank" href={{{[tag[IncomingItem]!has[date_received]has[tracking_number]get[tracking_number]join[,]addprefix[https://t.17track.net/en#nums=]]}}} >Track All</a>

You can also eliminate the "has[tracking_number]" from the filter, since get[tracking_number] will only return a result if the field exists.  Thus:
<a target="_blank" href={{{[tag[IncomingItem]!has[date_received]get[tracking_number]join[,]addprefix[https://t.17track.net/en#nums=]]}}} >Track All</a>

-e

David

unread,
Jun 29, 2020, 2:08:01 PM6/29/20
to TiddlyWiki
Thanks Eric!  I had actually found the join operator, but the example had it with a + sign and I tried as many permutations as I could which did not work.
Reply all
Reply to author
Forward
0 new messages