> I want to create a list of tiddlers ordered by the date the tiddler
> was last opened.
> I can use the For Each Tiddler functionality to create the list
> ordered by date 'created' or 'modified' e.g.
> So my question:  What can i substitute for 'tiddler.created' in the
> above piece of code to give me the tiddlers ordered by when they were
> last opened?

First, you need to actual keep track of when each tiddler is opened.
To do this, you can *hijack* the TW core's displayTiddler() function,
like this:

//{{{
Story.prototype.save_displayTiddler=Story.prototype.displayTiddler;
Story.prototype.displayTiddler=function(srcElem,tiddler) {
        this.save_displayTiddler.apply(this,arguments);
        var title=(tiddler instanceof Tiddler)?tiddler.title:tiddler;
        if (config.options.chkTrackViews && store.tiddlerExists(title))
                store.setValue(title,'viewed',new Date());
}
//}}}

Put the above code into a tiddler tagged with systemConfig (i.e., make
it a plugin).  This code first invokes the default core processing (to
display the tiddler), and then, if the tiddler actually exists, and
the 'chkTrackViews' option is enabled, it writes a *custom field*
named 'viewed', containing the current date/time, to the tiddler.

Note: writing the custom field to the tiddler means that every time
you visit a tiddler, the document will become 'dirty' (in need of
saving).  The chkTrackViews option allows you to enable/disable
updates to the 'viewed' field, so that you can avoid making document
changes when you don't want them.

To set/clear the chkTrackViews option, you will need to add a checkbox
somewhere in your document (e.g., OptionsPanel), like this:
   <<option chkTrackViews>> track tiddler views
Then, after you save-and-reload and enable the checkbox, every time a
tiddler is opened, the 'viewed' field for that tiddler will be
updated.  If you clear the checkbox, the most recent 'viewed' values
will be retained, but not updated.

Finally, to create date-ordered <<forEachTiddler>> 'reports' based on
the 'last viewed' field values, you can refer to:
   tiddler.fields.viewed

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlywiki@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.

Reply via email to