TiddlyWiki tiddlers by field name, sorted by date?

I needed to search for Tiddlers by tag name, then open them in descending creation date order. Sounds simple and it is, but ….

Replace a Word based system with a more light weight web style? TiddlyWiki is a good approach to try first. However, unless you use TiddlyWiki a lot, it can take a while to grok.

This is posted, in case someone has need of example programming. Note I’m not a TiddlyWiki expert, so just use this as a start if it helps. Would have posted it to the TiddlyWiki forum but didn’t see how to post source code.

I needed to search for Tiddlers by tag name, then open them in descending creation date.

Sounds simple and it is, but I had to access the TiddlyWiki source to see how to do it once I got a hint on the TiddlyWiki forum.

Put this source into a new Tiddler, for example, named openStatusTiddlers. Note the improved version in the comment by enrike on Dec 4.

// based on sample code by Eric Shulman
var fieldname='tags'; // put in what you want 
var fieldvalue='status'; // same thing 
var tidlist=[]; 

// iterate thru tiddlers and add matching to array.
   if (store.getValue(title,fieldname)==fieldvalue) {

// comparison closure for array sort.
function sortCreation(tA,tB){
    return store.fetchTiddler(tB).created - store.fetchTiddler(tA).created


// now show them in the 'story' object, which is the visible tiddlers.

Button to show the content
Then I needed a ‘button’ to invoke that tiddler. I created some inline html in the MainMenu:

   <hide linebreaks> 
      <<JsDoIt 'show status' 'execute javascript tiddler(s)' 'openStatusTiddlers'>>

That uses the jsDoIt macro and HTMLFormattingPlugin.

Also in the MainMenu tiddler I’m considering putting in a list of the status tiddlers. One approach is using the forEachTiddlerMacro:

        '"[[" + tiddler.title + "]]n"'
        end 'count+" Tiddlers foundn"'
        none '"No Tiddlers foundn"'

Show when page is loaded
Finally, I wanted these found tiddlers to open when the TiddlyWiki page first loads. For this I created another Tiddler that is put into the “DefaultTiddlers” Tiddler (which opens any included Tiddlers).
That Tiddler contains the same JavaScript as in listing one above.

Why a Single Page Wiki?
In Wikipedia there is an entry for a Single-Page Application (SPA). This is not exactly the same thing. In that entry the SPA as a functional organization is emphasized. In TiddlyWiki there is an additional physical structure, it is a single page or document.

Some SPAs may be executed from a local file using the file URI scheme. This gives users the ability to download the SPA from a server and run the file from a local storage device, without depending on server connectivity. If such a SPA wants to store and update data, it must be self-modifying. That is, the SPA must be capable of writing itself to disk, including a representation of the state that is to be persisted. Such applications benefit from advances available with HTML5, particularly Web Storage.

There are advantage to this single file approach. First is the small footprint, second is its mobility. Another important reason is usefulness over time. In a reporting or documentation that uses MS Word or any other proprietary (even PDF docs) application, there are no guarantees that a document will be readable by future applications. A TiddlyWiki, on the other hand includes it’s own software and unless there is a breaking change in JavaScript and the whole web stack, will be usable. (I hope!).

Gave some example JavaScript code to use in TiddlyWiki to use in a HTML replacement for status documents in MS Word. When the TiddlyWiki page is opened the list of status entries are shown in descending date order.

Probably not the best approach, but enough to see if it is viable.

Single-Page Application
open multiple tiddlers macro forum thread.
jsDoIt macro
My question posted on forum

10 thoughts on “TiddlyWiki tiddlers by field name, sorted by date?”

  1. hi, I am a newie to Tiddywiki and I dont understand very well how to actually implement myself your solution into my code.

    I understand I need to install jsDoIt macro and HTMLFormattingPlugin. I am not sure I need forEachTiddlerMacro. I installed it just in case …

    What I dont get is if I need the code you describe the “Solution” area here above. Do I need to paste that into the tiddlywiki source somewhere?

    Sorry I dont understand very well yet the insides of Tiddywiki, just learning now.


  2. enrike:

    Now that I reread the post, I see how vague it is. Unfortunately, this was done a while back, I need to study it again. But it did work.

    The first source code shown in the “solution” section must be put in its own Tiddler. In my experiment, that tiddler is named “openStatusTiddlers”.

    Ultimately, when you create an actual status tiddler (which are just normal tiddlers with a tag name of “status”, the script will open it in the TiddlyWiki UI.

    So, I created a Tiddler with a name of Mar15 and type tag of status. Clicked the “Show status” in the left hand main menu and that Mar15 tiddler opened up in the content area. Wow, it still works.

    — Josef

      1. Glad to hear it.

        I tweaked the blog post a little, but it needs much more to make it really usable. Oh well.

        Now, my next task is how to use Forms in a TiddlyWiki.

  3. thanks for the quick reply. It does not work for me, I am surely missing something. I am not yet very familiar with Tiddlywiki concepts so I might have installed wrong some of the plugins.

    I am familiar with Drupal so I think it is weird that this type of functionality (link that opens all posts with X tag) is not built in the core

    1. This modification of the loop area of your code should display also Tiddlers that are tagged “status” but also have more tags

      // iterate thru tiddlers and add matching to array.
      var vals = store.getValue(title,fieldname).split(” “);
      for (i=0; i <= vals.length; i++)
      if (vals[i] == fieldvalue) {

    1. When you open the ‘ControlPanel’ via the sproket icon, you can change the title and subtitle of the TiddlyWiki itself.

      But, yes I don’t see a ‘main’ either. I guess you just create a Main tiddler and make it the first default tiddler?

Leave a Reply

Your email address will not be published. Required fields are marked *