Using data dictionary for variable lookup

105 views
Skip to first unread message

Chris Brouwer

unread,
Feb 5, 2019, 8:46:38 AM2/5/19
to TiddlyWiki
Hello all,

I have the following situation, but can't acheive my goal. What am I doing wrong here ?

I hav a Datatiddler containing country codes (abbreviations) as indices and a sort code as values, like this:

CZ:01
SK:02
HU:03
RO:04
SRB:05

I have a tiddler with a Select widget, where I let the user choose a country code.
The resulting code is correctly placed in the "country" field. So far so good.

Here's the catch:
I also would like to place the sort code in a seperate field of the same tiddler. But accessing the DataTiddler seems to work only when I use a hardcoded countrycode, like {{landcodes##RO}}.

But what I would like is: {{landcodes##<<land>>}}, or whatever way to get to the correct value. I have tried constructs with "<<", "$(", '"""$' but nothing seems to do the trick.

Any suggestions ?

Here is the contents of my test-tiddler:
-----
\define update-sort()
<$vars lnd={{!!land}} >
<$action-setfield $tiddler=<<currentTiddler>> $field="sort" $value={{landcodes##<<lnd>>}} />
</$vars>
\end

\define getLand()
<$select tiddler=<<currentTiddler>> field="land" actions=<<update-sort>> >
  <$list filter='[[landcodes]indexes[]sort[title]]' listItem=selectedList >
      <option value=<<selectedList>>><$view field='title'></option>
  </$list>
</$select>
\end

<<getLand>>
-----

S. S.

unread,
Feb 5, 2019, 12:12:48 PM2/5/19
to TiddlyWiki

Chris,

This may be one way to do it (hopefully) :


\define getLand()
<$select tiddler=<<currentTiddler>> field="land" actions="<$action-setfield sort={{landcodes##$(sort-code)$}}/>">

<$list filter='[[landcodes]indexes[]sort[title]]'>
<option value=<<currentTiddler>>><$view field='title'></option>
</$list>
</
$select>
\end

<$set name="sort-code" value={{!!land}}>
<<getLand>>
</$set>

S. S.

unread,
Feb 5, 2019, 12:43:55 PM2/5/19
to TiddlyWiki

After reading THIS POST - I thought I'd try another way, which seems to work just as well.


\define getLand2()
<$select field="land" actions='<$action-setfield sort={{{[[landcodes]getindex{!!land}]}}}/>'>

<$list filter='[[landcodes]indexes[]sort[title]]'>
<option value=<<currentTiddler>>><$view field='title'></option>
</$list>
</
$select>
\end

<<getLand2>>

I also removed the :  tiddler=<<currentTiddler>> : as that is the default for the $select widget.


Chris Brouwer

unread,
Feb 5, 2019, 1:13:19 PM2/5/19
to TiddlyWiki
Thanks! That's the trick!

I now use this second version. I will use this info to learn form it.

I had not thought of the possibility to use the filter-syntax to set the value. 
Reply all
Reply to author
Forward
0 new messages