How to build an external href from values in fields

HI, very new to TW5 andI just can’t get the syntax right for this. I’m trying to make the href part of an external link from values in the fields of a tiddler. I feel like this should work:

The tiddler has two fields defined:
lat:123.12
lon:-30.23

Tiddler text is:

<a href="http://mydomain.com?lat={{!!lat}}&lon={{!!lon}}">test</a>

I would expect the produced link would be

http://mydomain.com?lat=123.12&lon=-30.23

but the link that is built is:

domain.com/?{{!!lat}}&{{!!lon}}

No transclusion seems to be happening?

What is the right incantation for this?

Thanks so much. TW5 looks amazing but I’m still trying to get my head around it.

Widget and HTML parameter values (e.g., the href value in <a href=...>) are not “wikified”, so the embedded transclusions are left as-is.

However, you can use “filtered transclusion” to construct the entire href parameter value, like this:

<a href={{{ [[http:/mydomain.com?lat=]] [{!!lat}] [[&lon=]] [{!!lon}] +[join[]] }}}>test</a>

-e

1 Like

Hey! I like the use of join[] instead of many addsuffix! Very elegant!

Fred

One thing to be careful of when using the +[join[]] technique…

If any of the text “pieces” occurs more than once, like this:

<$let quotedvalue={{{ [["]]  [{!!somefield}] [["]] +[join[]] }}}>

then only the last instance of [["]] will be kept because list items are “dominantly appended” which means that each item must occur only once.

To prevent this, you can use the “=” filter run prefix, like this:

<$let quotedvalue={{{ =[["]]  [{!!somefield}] =[["]] +[join[]] }}}>

In the above example, =[["]] allows both quotes to remain in the list.

In fact, it’s probably best to always use the “=” filter run prefix just to be sure you don’t unintentionally have repeated values, like this:

<$let quotedvalue={{{ =[["]]  =[{!!somefield}] =[["]] +[join[]] }}}>

In this way, if the contents of somefield is actually ", then you will get """ as a result (i.e, a “quoted quote” ) instead of just ".

-e

3 Likes

Excellent tip but I think there is a typo in there. The [{!!somefield}} terms should be [{!!somefield}] .

I spend a lot of time chasing down similar little subtle things like tabs, trailing spaces and em/en dashes looking like hyphens.

/Mike

fixed typos. Thanks.