Refresh tiddler automatically

119 views
Skip to first unread message

Soren Bjornstad

unread,
Jun 26, 2021, 11:05:15 PM6/26/21
to TiddlyWiki
Has anyone found a way to make TiddlyWiki re-render a part of the page template periodically? I'd like to have a section in my page template that does a calculation based on the current time, and would love if I didn't have to click a button all the time to update it. Maybe some kind of event that's scheduled in JavaScript and fires every minute?

I did find this interesting thread, but it doesn't offer any kind of timer-based refresh.

Eric Shulman

unread,
Jun 27, 2021, 12:57:27 AM6/27/21
to TiddlyWiki
On Saturday, June 26, 2021 at 8:05:15 PM UTC-7 Soren Bjornstad wrote:
Has anyone found a way to make TiddlyWiki re-render a part of the page template periodically?
I'd like to have a section in my page template that does a calculation based on the current time, and would love if I didn't have to click a button all the time to update it. 
Maybe some kind of event that's scheduled in JavaScript and fires every minute?

My TiddlyTools Timer functions can do this.

1) Copy the $action-timeout widget from 

2) Create a "MinuteTickerStartup" tiddler, tagged with $:/tags/StartupAction, containing:
\define minute_ticker() <$action-setfield $tiddler="$:/temp/time/minuteticker" text=<<now [UTC]0hh0mm0ss>> />
<$action-timeout interval=60000 actions=<<minute_ticker>> />

3) In a tiddler tagged with $:/tags/PageTemplate, put the content you want to automatically re-render each minute, like this:
<$vars ticker={{$:/temp/time/minuteticker}}>
   *** content you want to re-render ***
</$vars>

Notes:
1) MinuteTickerStartup is invoked once when you load your TiddlyWiki and sets up an javascript "interval" timer that is triggered every minute (60000 milliseconds)
2) The ticker action updates the contents of $:/temp/time/minuteticker to contain the current time (0hh0mm0ss)
3) The $vars "wrapper" in the page template tiddler creates a refresh dependency associated with the current value in $:/temp/time/minuteticker

The result is that whatever content is in your page template will be re-rendered once per minute.  Q.E.D.

enjoy,
-e

Soren Bjornstad

unread,
Jun 27, 2021, 11:45:26 AM6/27/21
to TiddlyWiki
Eric,

This worked perfectly! Thanks for the widget and the instructions.

Soren Bjornstad

unread,
Jun 27, 2021, 3:55:56 PM6/27/21
to TiddlyWiki
OK, I started having a major problem which took me a good hour to debug…but I have a fix. When I tried to use the TiddlyWiki CLI (for instance, with a --savewikifolder), it would hang indefinitely, because it is waiting on the timer to be torn down before terminating. Fortunately, there is a tag $:/tags/StartupAction/Browser which invokes the timer setup only when viewing the wiki in the browser. So I just removed $:/tags/StartupAction and added that one, and now it's working fine again.

Eric Shulman

unread,
Jun 27, 2021, 4:35:25 PM6/27/21
to TiddlyWiki
On Sunday, June 27, 2021 at 12:55:56 PM UTC-7 Soren Bjornstad wrote:
OK, I started having a major problem which took me a good hour to debug…but I have a fix. When I tried to use the TiddlyWiki CLI (for instance, with a --savewikifolder), it would hang indefinitely, because it is waiting on the timer to be torn down before terminating. Fortunately, there is a tag $:/tags/StartupAction/Browser which invokes the timer setup only when viewing the wiki in the browser. So I just removed $:/tags/StartupAction and added that one, and now it's working fine again.

Nice catch!  I don't use the CLI much at all, so that issue never came up for me.  I've updated http://tiddlytools.com/timer.html#TiddlyTools%2FTime%2FTicker to use $:/tags/StartupAction/Browser instead of $:/tags/StartupAction so that other won't have the same issue when using the default ticker.

Note: I've also done a feature update to http://tiddlytools.com/timer.html#TiddlyTools%2FTime%2FCalendar so that calendar dates now show alarms and timers in addition to events and tiddler changes.  If you prefer, you can use the Calendar Settings (gear icon) to omit alarms and/or timers from the Calendar display.  You can also change the date background color for alarms and/or timers.  By default, dates with alarms will use "OrangeRed" and dates with timers will use "LightYellow" .

enjoy,
-e
Reply all
Reply to author
Forward
0 new messages