Hi everybody

After tinkering with the source code of StorySaverPlugin, I've found
the answer to my own query (and maybe others'). I post it here for
whomever wants it. It uses inlineJavascriptPlugin and is certainly not
optimized ;-)
What it does: checks for a certain field==value among all tiddlers,
lists all positives in a given Tiddler tid (in my example it is called
'CurrentTiddlers'), closes all tiddlers and then opens the ones listed
in CurrentTiddler.

<<tiddler WriteTiddlersWith##script>>
/%
!script
//
<script label="WriteTiddlersWith">
   var tid='CurrentTiddlers';
   var fieldname='yourfield'; // put in what you want
   var fieldvalue='yourvalue'; // same thing
   var tidlist=[];
// gets in tidlist all tiddlers satisfying a given condition
   store.forEachTiddler(function(title,tiddler){
//      var t=store.getTiddler(title);
      var val=store.getValue(title,fieldname);
      if (val==undefined) return;
      if (val==fieldvalue) tidlist.pushUnique('[['+title+']]');
   });
   tidlist=tidlist.join('\n');
   var t=store.getTiddler(tid); var tags=t?t.tags:[];
   store.saveTiddler(tid,tid,tidlist,config.options.txtUserName,new
Date(),tags,t?t.fields:null);
   story.closeAllTiddlers();
 
story.displayTiddlers(null,store.getTiddlerText(tid).readBracketedList());
</script>
!end
%/

Scalpa


On Feb 15, 10:45 am, Scalpa <[email protected]> wrote:
> Thanks Eric,
>
> It looks obvious once you see it !
> I managed to make it work, piecing it together with Morris Gray's
> syntax (see below). However your script assumes the field contains as
> values tiddler names, which my script does not. I just want to filter
> by field value, eg whenever field 'time' == value 'now' display thetiddlers. 
> I added a condition, but don't see how to add to the
> 'titles' list the tiddler title instead of 'val'. (The truth being I
> don't know JS ;-) Any help ?
>
> Scalpa
>
> <<tiddler MyOpenTiddlers##script>>
> /%
> !script
> <script label="MyOpenTiddlers">
>    var titles=[];
>    store.forEachTiddler(function(title,tiddler){
>       var val=store.getValue(title,'time');
>       if (val==undefined) return;
>       if (val=='now') titles.pushUnique(val);
>    });
>    story.displayTiddlers(null,titles);
> </script>
> !end
> %/
>
>  and here's a forEachTiddler loop that lists what I want, but inside a
> tiddler instead of opening all the relevanttiddlers.
>
> <<forEachTiddler
>    where
>       ' store.getValue(tiddler,"time") == "now" '
> write '"[["+tiddler.title+"]] "'>>
>
> On Feb 13, 8:31 pm, Eric Shulman <[email protected]> wrote:
>
> > > However I cannot make the above script to work ! I get the following
> > > message
> > > TypeError: store.displayTiddlers is not a function
>
> > oops... typo!  that should be story.displayTiddlers(...)  not
> > store.displayTiddlers(...)
>
> > The "store" functions are related to saving/retrieving/searching
> > tiddler data.
> > The "story" functions are related to rendering/displaying content.
>
> > sorry for the confusion...
>
> > -e

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

Reply via email to