Insert text depending on field value

96 views
Skip to first unread message

Ste Wilson

unread,
Jul 22, 2016, 4:14:09 AM7/22/16
to TiddlyWiki
After using Steve Kimmel's Mathcell which, among other things, allows you to edit field values in line and in the non edit view (presentation view?) I was wondering if it was possible to use a macro or widget or some other magic to insert different text or transclusion into the tiddler depending on the field value?

So for example if the field was 'answer' and the value was two the text might read... Its good but its not right.... If the value were three then the text might read... Correct...

Thanks

Stephen

http://stephenteacher.tiddlyspot.com/

c pa

unread,
Jul 22, 2016, 11:50:50 AM7/22/16
to TiddlyWiki
Try building a tiddler something like this (correctanswer ans sentence are fields you need to add)

title: "Question1"
correctanswer: "five"
sentence: "I have <<findanswer>> fingers"
text="""

\define Get_Answer_Text(question)
    <$view tiddler="$:/state/answers/$question$" />
\end
\define Edit_Answer_Text(question)
    <$edit-text tag="input" tiddler="$:/state/answers/$question$" />
\end
\define findanswer()
    <$macrocall $name="Get_Answer_Text" question=<<currentTiddler>> />
\end
The sentence is: ''{{!!sentence}}''

How many fingers do you have?
<$macrocall $name="Edit_Answer_Text" question=<<currentTiddler>> />

<$reveal type="match" state="$:/state/answers/Question1" text={{!!correctanswer}}>
That is correct!
</$reveal>

<$reveal type="nomatch" state="$:/state/answers/Question1" text={{!!correctanswer}}>
That's good but its not right. If your answer was {{!!correctanswer}} then the text might read
</$reveal>

"""

Ste Wilson

unread,
Jul 30, 2016, 12:02:42 PM7/30/16
to TiddlyWiki
Sorry for the late reply. Cheers for that. It got me going on the right lines.

Have got a toddler working here:
stephenteacher.tiddlyspot.com/#worked%20eg%20test

Reply all
Reply to author
Forward
0 new messages