Linking to Field Values

130 views
Skip to first unread message

Merry Machiavelli

unread,
Jun 26, 2021, 7:10:43 PM6/26/21
to TiddlyWiki
Hello, I think this is a pretty basic problem, but I've not been able to figure out how to do it. 

Within tiddlywiki, I have profiles for made-up individuals. I have birthcountry of each individual recorded as a field. I also have wikipedia-style sideboxes with individuals date of birth, date of death, parentage, children....etc and birthcountry as well.

All I want to do is have it so that I can use the birthcountry field to supply a value that I can use as both text and a link to another tiddler.

For example: 
John Smith
Born - 04/05/1872 - Fantasyshire, MadeupLand (with "MadeupLand" value drawn from the field and also used link to a tiddler with the title "MadeupLand")

Currently, I can retrieve the field value:

<$view field=birthcountry/>

And I can manually link to 'MadeupLand':

<$link to="MadeupLand"></$link>

But putting them together like this: 

<$link to=<$view field=birthcountry/></$link>

Does not work, I just get "true</$link>"

Any help would be much appreciated!

Eric Shulman

unread,
Jun 26, 2021, 7:24:24 PM6/26/21
to TiddlyWiki
On Saturday, June 26, 2021 at 4:10:43 PM UTC-7 merry.ma...@gmail.com wrote:
All I want to do is have it so that I can use the birthcountry field to supply a value that I can use as both text and a link to another tiddler.
Currently, I can retrieve the field value:
<$view field=birthcountry/>
And I can manually link to 'MadeupLand':
<$link to="MadeupLand"></$link>
But putting them together like this: 
<$link to=<$view field=birthcountry/></$link>
Does not work, I just get "true</$link>"

Try this:
<$link to={{!!birthcountry}} /> 

enjoy,
-e

Soren Bjornstad

unread,
Jun 26, 2021, 7:26:39 PM6/26/21
to TiddlyWiki
Hi Merry,

This isn't valid XML/HTML/wikitext:

<$link to=<$view field=birthcountry/></$link>

You can never nest widgets within attributes of other widgets like this (side note: notice that even if this was allowable, you would be missing a closing > after the /> to finish the opening $link tag). More generally, it might be worth learning now that in an attribute like to=, you can do exactly one of four things in TW:
  • to="constant value" [see note 1]
  • to={{field transclusion}}
  • to={{{filtered transclusion}}}
  • to=<<variable transclusion>>
Any combination of these, or any other content, won't work. Here's a summary of the available transclusion syntax.

Fortunately, there's no need to use a $view widget here – you can just transclude the field with the double-brace syntax:

<$link to={{!!birthcountry}}/>

[1] There are three other ways you can quote the value: """triple quotes""", 'single quotes', and sometimes no quotes at all (if there aren't any spaces or special characters in the value).

Darth Mole

unread,
Jun 27, 2021, 12:04:01 AM6/27/21
to TiddlyWiki
@merry.ma

I just had a quick question about your process. I was wondering why you were using a field in the tiddler instead of [[MadeupLand]] to create a link? Or, I suppose for that matter, why not simply put the <?link to="MadeupLand"></$link> like you had? Not trying to be rude, truly just being curious about your process. Is there a particular reason or benefit you get from using the value of a field?

Thank you!

Merry Machiavelli

unread,
Jun 27, 2021, 5:07:48 AM6/27/21
to TiddlyWiki
Thank you so much @Soren Bjornstad, that works perfectly! I think I tried something close to that at one point, I just messed up the syntax!

@iamdar my use case is that I want to be able to mass-produce wikipedia-style bios for individuals, where the the same basic info comes up in multiple parts of the 'article'/tiddler. 

For example, in the opening line, it might say "John Smith was born in MadeupLand", the side bar might also mention he was born in MadeupLand. If I link both references to MadeupLand through a field i.e. using <$link to={{!!birthcountry}} /> then I only have to specify the country John Smith was born in once, in the field. If I iterate this process 100 times (using the same code for most of the body of the article, just customising it with novel information) it saves a lot of typing.

Another advantage is that it makes it easier to call groups of people who share a particle bit of vital information, without necessary creating a tag for, say, "born in 1872" (which, I could do...it just seemed clunky?). The main example that comes to mind is using surnames as a way to list every individual from a particular patrilineal lineage (assuming it's an unusual surname that unrelated individuals are unlikely to share within my group...I could also have a specific familyID field). 


Merry Machiavelli

unread,
Jun 27, 2021, 7:04:14 AM6/27/21
to TiddlyWiki
Sorry, supplemental question involving using fields¬

Another thing I want to do is use id and father-id / mother-id fields to automatically list the children of an individual. Ids are preferable to just names/titles, because of the chance of duplicate names.

How it might work is this. Say Robert Smith has two sons, John Smith and Peter Smith. That could be represented in fields like this:

(John Smith fields)

id: 365974-LlO
father-id: 634750-LiR

(Peter Smith fields)

id:  571157-OnU
father-id: 634750-LiR

(Robert Smith fields)

id:  634750-LiR
father-id: 612745-GbF

Now doing this <<list-links [field:father-id[634750-LiR]]>>

Works to retrieve the children of Robert Smith. However, that involves manually typing in Robert Smith's id. Instead I want something like this: <<list-links [field:father-id[{{!!id}}]]>>

But that doesn't work...

Eric Shulman

unread,
Jun 27, 2021, 8:13:52 AM6/27/21
to TiddlyWiki
On Sunday, June 27, 2021 at 4:04:14 AM UTC-7 merry.ma...@gmail.com wrote:
Now doing this <<list-links [field:father-id[634750-LiR]]>>
Works to retrieve the children of Robert Smith. However, that involves manually typing in Robert Smith's id. Instead I want something like this: <<list-links [field:father-id[{{!!id}}]]>>
But that doesn't work...

When specifying the parameter value for a filter operator, the type of brackets indicate the kind of parameter value you are using:

square brackets are for literal values,  e.g. [field:father-id[634750-LiR]]
angle brackets are for variable values, e.g., [field:father-id<somevariable>] 
curly braces are for field references, e.g.,  [field:father-id{!!id}] 

Also note that within filter syntax, use single brackets/braces, rather than the doubled brackets/braces that are used within regular wiki text syntax;
i.e., [634750-LiR] instead of [[634750-LiR]], <somevariable> instead of <<somevariable>>, and {!!id}} instead of {{!!id}}

enjoy,
-e
Reply all
Reply to author
Forward
Message has been deleted
0 new messages