Reference another tiddler's field by using a value in a custom field

113 views
Skip to first unread message

OGNSYA

unread,
Jun 25, 2020, 7:20:19 AM6/25/20
to TiddlyWiki
I want to transclude a custom field (let's call it myfield) of a tiddler (let's call it Source Tiddler) into another one (let's call it Target Tiddler).

I know I can just do this in Target Tiddler (assuming the Source Tiddler's name is "Source Tiddler"): {{Source Tiddler!!myfield}}

However, what if I want the name of that Source Tiddler to be dynamic, and come from a field in target Tiddler (let's call that field sourcename)?

Doing this, of course, shows me the name (just a string) of that source tiddler: {{!!sourcename}}

However it seems that I can't simply substitute that into the code above.
In other words, this doesn't work: {{{{!!sourcename}}!!myfield}}

I understand this is probably a very basic question. I suppose it has to do with the number of brackets, and how to communicate the fact that sourcename is something in the current tiddler, and myfield is something in another tiddler... However I can't figure out how to solve it.  I'm still very much a beginner in TW. Thanks in advance!

Michael Manti

unread,
Jun 25, 2020, 7:56:52 AM6/25/20
to TiddlyWiki
When trying to use information that's stashed in a field, I often find it easiest to use the widget syntax. In your case, I would use the transclude widget in the target tiddler.

<$transclude tiddler={{!!sourcename}} field="myfield"/>

TW Tones

unread,
Jun 25, 2020, 8:10:25 AM6/25/20
to TiddlyWiki
Ognsya,

to set a field value you must do it interactively or use a trigger like a button to trigger an action widget.

In your case the new field will be set to the value of the old field perhaps using actionsetfield.

Will that help you to the next step?

Regards
Tony

Eric Shulman

unread,
Jun 25, 2020, 8:53:41 AM6/25/20
to TiddlyWiki
On Thursday, June 25, 2020 at 5:10:25 AM UTC-7, TW Tones wrote:

to set a field value ...


That wasn't the question he asked!  He just wanted to *show* (not *set*) a field value stored in another tiddler.

-e

Eric Shulman

unread,
Jun 25, 2020, 8:53:52 AM6/25/20
to TiddlyWiki
On Thursday, June 25, 2020 at 4:56:52 AM UTC-7, Michael Manti wrote:
When trying to use information that's stashed in a field, I often find it easiest to use the widget syntax. In your case, I would use the transclude widget in the target tiddler.
<$transclude tiddler={{!!sourcename}} field="myfield"/>

You can also write it this way:
<$view tiddler={{!!sourcename}} field="myfield" />

or even this way:
<$tiddler tiddler={{!!sourcename}}>{{!!myfield}}</$tiddler>

-e

OGNSYA

unread,
Jun 25, 2020, 9:21:00 AM6/25/20
to TiddlyWiki
Thanks all for the help! This worked.

Just so I can learn with my mistakes, what was wrong about my thinking when I did this\?:
{{{{!!sourcename}}!!myfield}}

PMario

unread,
Jun 25, 2020, 10:32:18 AM6/25/20
to TiddlyWiki
On Thursday, June 25, 2020 at 3:21:00 PM UTC+2 OGNSYA wrote:
Thanks all for the help! This worked.

Just so I can learn with my mistakes, what was wrong about my thinking when I did this\?:
{{{{!!sourcename}}!!myfield}}

Your thinking is OK. ... But the TW parser can't handle nested constructions like this. ... There aren't enough "indications" for the algorithm to "guess" what is meant. .. So 1 more proof, that human brains are much more powerful (out of the box) than machine algorithms.

-m

Eric Shulman

unread,
Jun 25, 2020, 10:34:40 AM6/25/20
to tiddl...@googlegroups.com
On Thursday, June 25, 2020 at 6:21:00 AM UTC-7, OGNSYA wrote:
Just so I can learn with my mistakes, what was wrong about my thinking when I did this\?:
{{{{!!sourcename}}!!myfield}}

You can't nest syntax (i.e, using transclusion syntax *inside* of transclusion syntax)

This is, in part, because the TiddlyWiki language is *interpreted* in real-time rather than "compiled" ahead of time,
and the parser is based on linear pattern recognition using "regular expressions" (regexp) rather than a recursive algorithm.
If the TWCore used recursion, then the overhead for processing the syntax would rapidly overwhelm the performance

for example, you can't embed a macro inside another macro
<<something param:<<somethingelse>> >>

and you can't use widgets inside of a widget parameter
<$somewidget param=<$someotherwidget ... />

and you can't mix TW macro syntax *inside* a parameter value
<$somewidget param="some <<macro>> text" />

Note that you CAN use a macro as a *whole* widget parameter:
<$somewidget param1="some text" param2=<<somemacro ...>> />

You can also use an "inline filter" as a *whole* widget parameter:
<$somewidget param={{{ [...somefilter...] }}} />

This also applies to HTML syntax, where you can use macros as parameter values:
<div class=<<somemacro>> style=<<someothermacro>>>...</div>

but you can't write this:
<div class=<<somemacro>> style="color:<<someothermacro>>" >...</div>

However, there are some interesting techniques for getting around the problem.  For example,
<div class=<<somemacro>> style={{{ [[color:]addsuffix<somevariable>] }}} >...</div>
uses an inline filter to assemble the full style=... CSS syntax by appending the value of <somevariable> to some literal CSS syntax, [color:]

I know this seems very confusing, but it is *consistent*, even if it's not *conventional*...

-e

OGNSYA

unread,
Jun 25, 2020, 11:44:52 AM6/25/20
to TiddlyWiki
Thank you for the explanations!

They all make sense to me, though it will probably be a while until I fully "get it"...

TW Tones

unread,
Jun 25, 2020, 8:31:56 PM6/25/20
to TiddlyWiki
Ognsya,

I would just reinforce Eric previous answer is a small set of rules that would be worth memorising, to stop your mind imagining and attempting to code the impossible.
My life is easier since experience has told me to resist these intuitive but incorrect methods. You could say any nesting of things outside Eric's rules needs a closer look before use.

One not documented here, is when you are forced to wikify a variable or macro before use. 

I would hope we could provide a way to simplify this, the wikify issue, in the core, like a way to use a variable or macro as a parameter that causes a wikified version to be used. 

Regards
Tony

Mat

unread,
Jun 27, 2020, 6:44:21 AM6/27/20
to TiddlyWiki
Im surprised nobody has brought up putting it into a macro:

\define myTrans() {{$(tid)$!!$(field)$}}

<$vars tid=... field=... >
<<mytrans>>
</$vars>


Apropos what Eric wrote:
<div class=<<somemacro>> style={{{ [[color:]addsuffix<somevariable>] }}} >...</div>

Ha ha!!! It's fantastic that there IS a way but it is also fantastic how overly complex we sometimes are forced to make things.

Again, I'd instead propose a macro (which, of course, is also a workaround) like so

\define myDiv() <div class="$(class)$" style="color:$(color)$" >...</div>

<$vars class=... color=...>
<<myDiv>>
</$vars>

<:-)
Reply all
Reply to author
Forward
0 new messages