Using a variable to extract a sentence from a DataTiddler

110 views
Skip to first unread message

ParisWiki

unread,
Dec 4, 2015, 11:30:19 AM12/4/15
to TiddlyWiki
Hello,

I wish to use a variable to extract a sentence from a data tiddler.

The user chooses his/her own language and from there he/she should obtain a guide for a service in the right language.

Of course with the choice of language (choice ={{Language!!choix}} it easy to keep the same language in  all the tiddlers whose tag matches with the field "choix" in the tiddler "Language".

It is also easy to implement situations where various sentences are extracted from a data tiddler with the formula {{Data1r##zh}} in the case where the language is chinese (zh).

But in that case, the language is de facto hard coded.

I wish to simplify the number of patterns by using a variable for extracting data from my data tiddler(s). 

 I have built an exemple at http://jcg.tddlyspot.com.

Either I don't correctly manipulate the syntax of variables in TiddlyWiki (which is more than probable), or I am asking to much in willing extracts from a data tiddler thru a variable !

In other words, I would appreciate some guidance ...

Thank you in advance
JCG

Matabele

unread,
Dec 4, 2015, 12:18:46 PM12/4/15
to tiddl...@googlegroups.com
Hi

Combine the two variables with a macro:

\define sentence(data,language) $data$##$language$

Then reference this value like this: <<sentence dataone zh>>

or for variables (stored in a field), like this: <<sentence {{!!target}} {{!!language}}>>

regards

ParisWiki

unread,
Dec 4, 2015, 2:57:18 PM12/4/15
to TiddlyWiki
Hi Matabele,

I am still missing something.
The first solution, as it is, gives nothing useful to me.

The second proposal looks much more promising and gives {{Data1##fr}} if the language chosen is French or {{Data1##zh}} for Chinese, after adding the curly braces {{<sentence {{!!target}} {{!!language}}>>}}.

But it does not "resolve" the formula and certainly, as it is, does not extract data from my data tiddler Data1.

Did you try it and obtain the correct extraction?
What do I miss again ?

regards

Matabele

unread,
Dec 4, 2015, 11:41:03 PM12/4/15
to TiddlyWiki
Hi

This technique creates the TextReference as a string -- this reference still needs to be used to become wikified.

There's another method which may better suit your needs. The $transclude widget accepts a 'tiddler' attribute and an 'index' attribute:

<$transclude tiddler={{!!mydata}} index={{MySettings!!language}} mode="block"/>

-- may be used with a referenced variables, rather than a referenced fields:

<$transclude tiddler=<<mydata>> index=<<language>> mode="block"/>

regards

ParisWiki

unread,
Dec 5, 2015, 3:26:20 AM12/5/15
to TiddlyWiki
Thank you Matabele,

It works perfectly with


<$transclude tiddler={{!!mydata}} index={{MySettings!!language}} mode="block"/>

(remark: when using tiddler=<<mydata>> as per your second exemple, I got a transclusion error)

Thanks again,

Regards
Reply all
Reply to author
Forward
0 new messages