How to reset a state field when a tiddler is closed and reopened?

123 views
Skip to first unread message

Robert Paech

unread,
Jul 19, 2016, 7:11:58 AM7/19/16
to TiddlyWiki
I am trying to use TiddlyWiki to create a database of exercises.  The database includes descriptions on how to prepare for and execute an exercise, with corresponding videos for the preparation and execution movements.

My current intention is for each exercise tiddler to open with a thumbnail image of the exercise along with two buttons that will allow the user to view either the preparation or execution videos. In each case, the thumbnail image (or video) should be replaced with the preparation or execution video of the respective button when selected.

I have created the tiddler template below to include the videos in each exercise tiddler, and it pretty much does what I want, except for one problem, which I don't know how to solve.

What I would like to happen is that when the exercise tiddler is closed and reopened, the tiddler returns to the original state of showing the thumbnail image.  However, as I need to use a field or tiddler to store the button/reveal state, when I reopen an exercise tiddler it uses the last state value that was set.

Is there a way to use variables for this purpose or to reset a tiddler field when a tiddler is closed? Alternatively, is there a better way to solving my problem?

<$button><$action-setfield $tiddler="$:/exw/state/video" $value="prep"/>Preparation</$button>
<$button><$action-setfield $tiddler="$:/exw/state/video" $value="exec"/>Execution</$button>
<$reveal type="nomatch" state="$:/exw/state/video" text="image
">
<$button><$action-setfield $tiddler="$:/exw/state/video" $value="image"/>Reset</$button>
</$reveal>

<$reveal type="match" state="$:/exw/state/video" text="prep">
<video width={{$:/exw/setting/video-size}} autoplay src={{!!video-preparation}}/>
</$reveal>
<$reveal type="match" state="$:/exw/state/video" text="exec">
<video width={{$:/exw/setting/video-size}} autoplay loop src={{!!video-execution}}/>
</$reveal>
<$reveal type="match" state="$:/exw/state/video" text="image">
<$image width={{$:/exw/setting/video-size}} source={{!!image}}>
</$reveal>

c pa

unread,
Jul 19, 2016, 11:12:09 AM7/19/16
to TiddlyWiki
Robert,

You can do this if the user is opening the exercise tiddler from a button rather than a link. This means that in your index of exercises, rather than

[[exercise name]]    or <$link to="exercise name"> Exercise name</$link>

Use

<$button to="exercise name">
        exercise name
        <$action-setfield $tiddler="$:/state/whatever" text=""/>
</$button>


Robert Paech

unread,
Jul 20, 2016, 4:43:14 AM7/20/16
to TiddlyWiki
Thanks c pa,

I was thinking whether it's possible to perform the action prior to opening the exercise tiddler; however I use filters to search the exercises and generate the links through the list widget.

I think the solution you suggested would only work with static links to tiddlers, is that right? Is there a way that your solution could be used with dynamic links generated using filters?

Jed Carty

unread,
Jul 20, 2016, 5:25:45 AM7/20/16
to TiddlyWiki
You van use his solution with a list, you just make a template for the button and give that to the list widget.

Robert Paech

unread,
Jul 20, 2016, 5:45:40 AM7/20/16
to TiddlyWiki
Thanks for the fast responses.  Another lesson for me to always go back and read the reference manual even when I think I understand how something works.
Reply all
Reply to author
Forward
0 new messages