Put tiddler's field in an < a > href?

73 views
Skip to first unread message

David

unread,
Jun 29, 2020, 8:50:39 AM6/29/20
to TiddlyWiki
I have this code that tries to put a field value into a link, which seems logical, but doesn't work...

I also tried the transclude code...

<a href="https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=<$transclude field="tracking_number" />">USPS Tracking</a>

I had originally tried this code, but it seems that external links have to be put into the html anchor tag.

[[USPS Tracking|https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=<$transclude tiddler=<<item>> field="tracking_number" />]]

Thank you all!

Mark S.

unread,
Jun 29, 2020, 9:15:52 AM6/29/20
to TiddlyWiki
What you're trying to do is to concatenate the contents of a field with a string. There are a couple different approaches, often using helper macros. These days, I like to use the {{{ }}} wikitext and a filter that uses "addprefix" or "addsuffix". Like:

David

unread,
Jun 29, 2020, 10:02:02 AM6/29/20
to TiddlyWiki
Dangit.  you guys had told me that once before.  Sorry.  It just seems like it should work easier than that.

I guess it is because the html for the < a > tag is being parsed by TW and not just rendered as static maybe.

Thank you!

TW Tones

unread,
Jun 29, 2020, 10:21:07 AM6/29/20
to TiddlyWiki
David

One way to look at what you tried to do is give a parameter that was made of two parameters a literal and transclusion in the same parameter in this case href.

Imagin if you were tiddlywiki yourself. First you need to evaluate what the result of the transclusion is then remember it was part of the same value as the literal string then combine them and only then use the result as the value to pass as a parameter.

This is like Eisenstein sitting on a light beam. When you think about it from tiddlywikis's perspective you are asking too much. You should take responcibility for concatenation of disparit values before you ask tiddlywiki to consider it a single value for a parameter.

Does this make sense to you?

regards
Tony

David

unread,
Jun 29, 2020, 10:23:28 AM6/29/20
to TiddlyWiki
Okay, so a related question...

That worked great when I was inside the one tiddler that had that field. 

But what about being in a tiddler that is looping with the ListWidget over the tiddlers that all have tracking_number fields ? 

The variable item is being set for the loop, as the iterator.  So I tried this and it didn't work...


Thank you!


On Monday, June 29, 2020 at 9:15:52 AM UTC-4, Mark S. wrote:

TW Tones

unread,
Jun 29, 2020, 10:31:17 AM6/29/20
to TiddlyWiki
Tiddlywiki could be built to do what you asked of it. However you may have to give up other things it already does for you.

For example parmname={{!!fieldname}} not only transcludes the value found in fieldname but it also uses the same curly braces to delimit the beginning and end of the parameter. Imagin the fieldname value contained spaces or quotes or tiddler titles with square braces etc. If it did not also use the braces to delimit the beginning and end of the parameter you could be in trouble.

Then you asked it to understand parm="literal{{!!fieldname}}", you were asking too much. As I did until I sat on tiddlywiki shoulder and considered what I was asking from tiddlywiki perspective.

Regards
Tony

TW Tones

unread,
Jun 29, 2020, 10:38:50 AM6/29/20
to TiddlyWiki
David

When you use the triple curly braces the result is returned between the braces. It is not necessarily suitable for filters that generate a list because the whole list is passed as a single parameter.

I think this a case for putting that filter in to a list widget and generate multiple a tags. One for each result of the filter.

Regards
Tony

David

unread,
Jun 29, 2020, 10:41:54 AM6/29/20
to TiddlyWiki
Yeah, Tony, I think that does make sense.

In most scripting language that use html markup within them, like PHP, the < a > tag is not really parsed on a display page.  It's just a string literal, and PHP just looks inside that string to see if it finds some PHP code.  If it does, it replaces that code wherever it is found with whatever literal is the calculated result.

It appears that TW doesn't do it this way, (which is fine, I'm the one who has to get used to it) in that it seems to parse the < a > tag and it's attributes through it's own engine. From that perspective it makes perfect sense.

You know, I wouldn't expect so much of TW if you guys hadn't made it so good!  There are so many things about it where it is doing such smart stuff so easily.

Mark S.

unread,
Jun 29, 2020, 10:44:05 AM6/29/20
to TiddlyWiki
You're kind of making us squint through a keyhole. Why did you use the variable "item" ? There's probably a good reason, but with only this information it looks kind of arbitrary.

What I might do is not assign the variable item with the list widget, but inside it. Then your code might look like

<$list ...etc...>
<$vars item={{!!title}}>
... do something with <<item>> ...
</$vars>
</$list>

But, in this case, I don't see what the advantage of <<item>> is over <<currentTiddler>> .

In general, I would use a variable in a list only if the output is NOT an actual tiddler or if I didn't want the loop to track <<currentTiddler>> .  That is, sometime the output of a list might be a series of numbers. Those numbers don't exist as tiddlers, so they're good candidates as variables. Or sometimes a list widget is used to control number of iterations, so you might assign a variable "dummy" so that the original currentTiddler value doesn't get stomped on.

Eric Shulman

unread,
Jun 29, 2020, 10:45:15 AM6/29/20
to tiddl...@googlegroups.com
On Monday, June 29, 2020 at 7:23:28 AM UTC-7, David wrote:
But what about being in a tiddler that is looping with the ListWidget over the tiddlers that all have tracking_number fields ?  
The variable item is being set for the loop, as the iterator.  So I tried this and it didn't work...

Give this a try:
<a href={{{[<item>get[tracking_number]addprefix[https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=]}}}>USPS Tracking</a>

Start with the tiddler title stored in <item>
Then get the tracking_number field value from that tiddler
Then add the URL stuff onto the *front* of the retrieved value.

and remember...
"Give a man a fish and he will eat for a day. Teach a man to fish and he will decimate an entire ecosystem!"

:)

enjoy,
-e
 

Mark S.

unread,
Jun 29, 2020, 10:51:49 AM6/29/20
to TiddlyWiki


On Monday, June 29, 2020 at 7:41:54 AM UTC-7, David wrote:
In most scripting language that use html markup within them, like PHP, the < a > tag is not really parsed on a display page.  It's just a string literal, and PHP just looks inside that string to see if it finds some PHP code.  If it does, it replaces that code wherever it is found with whatever literal is the calculated result.

It will save yourself a lot of frustration if you start with a clean slate. Nothing from PHP, Javascript, etc. is going to directly map onto wikitext. We had a semi-famous, published developer here, and he was in a kind of state of disbelief as we tried to explain how things worked.

In TW, it's about widgets (especially the list widget), macros (which are also a kind of variable), filters, and transclusions. Those are the tools we're given, and this is the world we live in. It's easy. But it's very, very different.


Eric Shulman

unread,
Jun 29, 2020, 11:10:56 AM6/29/20
to TiddlyWiki
On Monday, June 29, 2020 at 7:45:15 AM UTC-7, Eric Shulman wrote:
Give this a try:
<a href={{{[<item>get[tracking_number]addprefix[https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=]}}}>USPS Tracking</a>

Start with the tiddler title stored in <item>
Then get the tracking_number field value from that tiddler
Then add the URL stuff onto the *front* of the retrieved value.

Note: if your <$list> widget just used the default "currentTiddler" variable, then you could simplify the above to:
<a href={{{ [{!!tracking_number}addprefix[https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=] }}}>USPS Tracking</a>

or, if you prefer:
<a href={{{ [[https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=]addsuffix{!!tracking_number}] }}}>USPS Tracking</a>

and, if you do want to use the "item" variable, you could still write one of the above... just wrap the whole thing inside a <$tiddler> widget, like this:
<$tiddler tiddler=<item>>
<a href={{{ [[https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=]addsuffix{!!tracking_number}] }}}>USPS Tracking</a>
</$tiddler>

-e

David

unread,
Jun 29, 2020, 12:40:46 PM6/29/20
to TiddlyWiki
Eric, Tony, and Mark,

Thanks so much for all your help.  I was using the << item >> var because it saw it somewhere and it worked for what I was using that was a bit different.  I have changed that code to not use the variable attribute for that listWidget and re-coded a few things and it is working well, and I like the dynamics of it. Thanks so much for that !!

And thanks so much for the other use case where I can bring in the addsuffix and prefix type operators, because I need that too!
Reply all
Reply to author
Forward
0 new messages