Help with ForEachTiddler

130 views
Skip to first unread message

magev958

unread,
Feb 10, 2011, 4:08:50 PM2/10/11
to TiddlyWiki
Hi, I been tinkering with TiddlyWiki for some time now and starts to
get the hang of it, but my programing skills is an empty hole.
I found great piece of code (I think it was here) for the plugin
ForEachTiddler that display just the first bit of every tiddler in
order. Works great, but I'd like to limit the number of tiddler it
displays to say 5. How do I get about to do that?

<<forEachTiddler
where
'tiddler.tags.contains("information")'
sortBy
'store.getValue(tiddler,"created")'
descending
write
'"\n@@font-size:1.5em;[["+tiddler.title+"]]@@@@color:#999; - " +
Date.convertFromYYYYMMDDHHMM(store.getValue(tiddler,"created")).formatString("YYYY/
0MM/0DD")+" - "+tiddler.modifier+"@@\n" +
"{{excerpt{\n" +
(tiddler.text.match("/%%/") ?
tiddler.text.substr(0,tiddler.text.indexOf("/%%/")) :
tiddler.text.substr(0,300)) +
" ...\n[[more ...|"+tiddler.title+"]]\n----\n}}}";'
>>

Thanks in advance/

Måns

unread,
Feb 10, 2011, 4:20:54 PM2/10/11
to tiddl...@googlegroups.com
Hi magev958

You'll need '(index < 5) ?

ForEachTiddler that display just the first bit of every tiddler in
order. Works great, but I'd like to limit the number of tiddler it
displays to say 5. How do I get about to do that?

Try (untested
)
<<forEachTiddler
 where
 'tiddler.tags.contains("information")'
 sortBy
 'store.getValue(tiddler,"created")'
 descending
 write
 '(index < 5) ?"\n@@font-size:1.5em;[["+tiddler.title+"]]@@@@color:#999; - " + 
Date.convertFromYYYYMMDDHHMM(store.getValue(tiddler,"created")).formatString("YYYY/
0MM/0DD")+" - "+tiddler.modifier+"@@\n" +
 "{{excerpt{\n" +
 (tiddler.text.match("/%%/") ?
 tiddler.text.substr(0,tiddler.text.indexOf("/%%/")) :
 tiddler.text.substr(0,300)) +
 " ...\n[[more ...|"+tiddler.title+"]]\n----\n}}}";'
>>

whatever

unread,
Feb 10, 2011, 4:21:26 PM2/10/11
to TiddlyWiki
<<forEachTiddler
where
'tiddler.tags.contains("information")'
sortBy
'store.getValue(tiddler,"created")'
descending
write
'(index < 5) ? tiddler.title+"\n" : ""'>>

That should do it, just replace tiddler.title+"\n" with your own code
in quotes. I had some trouble with your code, so you might want to
debug it. As far as I can tell, the quotes @@\n" + "{{excerpt{\n are
not necessary, since this is all a literal string.

w

magev958

unread,
Feb 10, 2011, 4:52:27 PM2/10/11
to TiddlyWiki
Wow, that was fast!
Thanks for your suggestion, unfortunate it did not work :(
When I add the

'(index < 5) ?

all I get is a error

<<forEachTiddler ...>>:SyntaxError: Parse error

The code is not mine, I found it in this forum so I don't know what
and how it works, but it shows the title, creator, date and the first
lines of the tiddler very beautiful :)

whatever

unread,
Feb 10, 2011, 5:10:37 PM2/10/11
to TiddlyWiki
This should do it:
<<forEachTiddler
where
'tiddler.tags.contains("information")'
sortBy
'store.getValue(tiddler,"created")'
descending
script
'
function getFirstLine(s) {
var m = s.match(/\s*(.*)/);
return m != null && m.length >= 1 ? m[1] : "";
}
' write
'(index < 5) ? "[["+tiddler.title+"]] - "+tiddler.creator+" -
"+tiddler.created+" - "+getFirstLine(tiddler.text)+"\n" : ""'>>

w

whatever

unread,
Feb 10, 2011, 5:12:05 PM2/10/11
to TiddlyWiki
Oh yeah, I think you might have forgot to add : "" at the end, that's
why you probably got the error.
w

On Feb 10, 10:52 pm, magev958 <magnus.ev...@gmail.com> wrote:

Måns

unread,
Feb 10, 2011, 5:56:24 PM2/10/11
to tiddl...@googlegroups.com
Now tested with your codesnippet - you'll need to replace the last ; with :"" as whatever says:
<<forEachTiddler 
 where 
 'tiddler.tags.contains("information")' 
 sortBy 
 'store.getValue(tiddler,"created")' 
 descending 
 write 
 '(index < 5) ?"\n@@font-size:1.5em;[["+tiddler.title+"]]@@@@color:#999; - " + Date.convertFromYYYYMMDDHHMM(store.getValue(tiddler,"created")).formatString("YYYY/0MM/0DD")+" - "+tiddler.modifier+"@@\n" +  "{{excerpt{\n" + (tiddler.text.match("/%%/") ? tiddler.text.substr(0,tiddler.text.indexOf("/%%/")) :  tiddler.text.substr(0,300)) + " ...\n[[more ...|"+tiddler.title+"]]\n----\n}}}":""' >> 

Cheers Måns Mårtensson

Måns

unread,
Feb 10, 2011, 6:16:36 PM2/10/11
to tiddl...@googlegroups.com
An alternative idea:
You could use a hidden section "note" instead of firstlines (i.e some comment) and use Eric's EditSectionPlugin like this:

<<forEachTiddler 
 where 
 'tiddler.tags.contains("information")' 
 sortBy 
 'store.getValue(tiddler,"created")' 
 descending 
 write 
 '(index < 5) ?"\n@@font-size:1.5em;[["+tiddler.title+"]]@@@@color:#999; - " + Date.convertFromYYYYMMDDHHMM(store.getValue(tiddler,"created")).formatString("YYYY/0MM/0DD")+" - "+tiddler.modifier+"<<editSection [["+tiddler.title+"##note]] ✎\>\>@@\n" +  "><<tiddler [["+tiddler.title+"##note]]\>\>\n----\n":""' >> 

Cheers Måns Mårtensson

magev958

unread,
Feb 11, 2011, 2:20:19 AM2/11/11
to TiddlyWiki
Yes!!!
I finally got it to work! :)
Thanks very much, I would never have figured it out by my self
Reply all
Reply to author
Forward
0 new messages