FET Results with Table Headers

79 views
Skip to first unread message

James

unread,
Mar 28, 2012, 6:37:51 AM3/28/12
to TiddlyWiki
Hello everyone,
I am a non programmer and have very little skills using TiddlyWiki and
the various Plugins.
I have tried searching for an answer to my question but with no
success.

I have a tiddler that lists a number of books and their authors.
<<forEachTiddler
where
'tiddler.tags.contains("book")'
sortBy
tiddler.data("author")
ascending

write
'"|"+tiddler.data("author")+"|[["+tiddler.title+"]]|\n"''
>>

I would like to modify this so that it shows a table like so:

|Author|Book Title|
|"+tiddler.data("author")+"|[["+tiddler.title+"]]|

Can you please help - It seems so simple but I don't know javascript.

On a similar note, is it possible to automate such a list.
Go thorugh each Tiddler and put each field name in the table header
and the data in the table cells without having to know the data field
names or type the script.

Any help you could give me would be much appreciated.

Måns

unread,
Mar 28, 2012, 5:35:15 PM3/28/12
to TiddlyWiki
Hi James

> I have a tiddler that lists a number of books and their authors.
> <<forEachTiddler
>     where
>         'tiddler.tags.contains("book")'
>     sortBy
>         tiddler.data("author")
>          ascending
>
>     write
>       '"|"+tiddler.data("author")+"|[["+tiddler.title+"]]|\n"''

This might do what you want (untested...):

<<forEachTiddler where 'tiddler.tags.contains("book")'
sortBy
tiddler.data("author")
ascending
write
'"|Author|Book Title|h\n||"+tiddler.data("author")+"|[["+tiddler.title
+"]]|\n"'>>

"\n" (without the quotes) creates linebreaks and the "h" (without the
quotes) formats the row as a header..

Cheers Måns Mårtensson

James

unread,
Mar 29, 2012, 5:57:15 AM3/29/12
to TiddlyWiki
Thanks Måns,
just one litte problem with your script.

The Table output creates
|Author|Book Title|
| | Author|Book Title|

For some reason the cells do not line up properly, the headers are
fine but ther appears to be an extra cell.
Any idea what's causing this?

Cheers James

On Mar 28, 10:35 pm, Måns <humam...@gmail.com> wrote:
> Hi James

whatever

unread,
Mar 29, 2012, 6:32:52 AM3/29/12
to TiddlyWiki
This should work. fET has a nice keyword called "begin", which you can
use for table headers.

<<forEachTiddler
where
'tiddler.tags.contains("book")'
sortBy
tiddler.data("author")
ascending

write
'"|"+tiddler.data("author")+"|[["+tiddler.title+"]]|\n"'' begin
'"|Author|Book Title|h\n"'>>

The "h" before the "\n" is optional and gives the header row the
header class.

w

James

unread,
Mar 29, 2012, 7:12:57 AM3/29/12
to TiddlyWiki
Hi whatever,
thanks for your reply.
When I put your code in the tiddler I get this error message.
<<forEachTiddler ...>> : Extra parameter behind 'write' : begin|Author|
Book Title|h\n

whatever

unread,
Mar 29, 2012, 7:21:14 AM3/29/12
to TiddlyWiki
Ah, yes, I missed one of your apostrophes.

<<forEachTiddler
where
'tiddler.tags.contains("book")'
sortBy
tiddler.data("author")
ascending

write
'"|"+tiddler.data("author")+"|[["+tiddler.title+"]]|\n"' begin
'"|Author|Book Title|h\n"'>>

That should do it.

James

unread,
Mar 31, 2012, 10:14:22 AM3/31/12
to TiddlyWiki
Hi Whatever,
thanks again for the reply, but I still get the same error with the
code you provided.

cmari

unread,
Mar 31, 2012, 3:46:30 PM3/31/12
to tiddl...@googlegroups.com
I have tiddlers with those exact tags and fields except capitalized, so I copied and pasted whatever's code, changed the case of the first letters, and it worked for me.
One thing to try would be limiting the "where" criteria so that it only finds tiddlers that actually contain the field "author":

where
       'tiddler.tags.contains("Book")&&tiddler.data("Author")'

cmari

James

unread,
Apr 2, 2012, 6:12:02 AM4/2/12
to TiddlyWiki
Hi cmari,
when I remove

begin
'"|Author|Book Title|h\n"'

the code works fine, even with my tags "book" and "author".

The problem must be with the begin statement ?
I don't know why this is not working for me and yet yours works ok.

~ James

whatever

unread,
Apr 2, 2012, 6:32:44 AM4/2/12
to TiddlyWiki
Can you provide a sample of your wiki so we can take a look? Perhaps
something else interferes with fET.

w

James

unread,
Apr 3, 2012, 6:06:51 AM4/3/12
to TiddlyWiki
Hi whatever,
I'm sorry but I don't know how to provide you with a sample of my
wiki. Where would I upload it?

~ James

James

unread,
Apr 10, 2012, 6:54:13 AM4/10/12
to TiddlyWiki
Hi whatever,
I have uploaded a copy of my tw as requested, I hope it helps.

http://www.jamesmcl.co.uk/tw/MyBooks.html

Thanks,
James

whatever

unread,
Apr 10, 2012, 7:39:59 AM4/10/12
to TiddlyWiki
Remove "Plugin ForEachTiddler", it's an older version of fET and
interferes.

Then
<<forEachTiddler
where
'tiddler.tags.contains("book")'
sortBy
tiddler.data("author")
ascending
write
'"|"+tiddler.data("author")+"|[["+tiddler.title+"]]|\n"' begin
'"|Author|Title|h\n"'>>
should work. It did for me.

w

James

unread,
Apr 10, 2012, 10:09:02 AM4/10/12
to TiddlyWiki
Thanks whatever, it worked for me too. I removed the "Plugin
ForEachTiddler" as you said.
Thanks also to Måns and cmari for your help with this problem.
~James
Reply all
Reply to author
Forward
0 new messages