Brief dictionary possible using TiddlyWiky ?

466 views
Skip to first unread message

Frank

unread,
May 28, 2009, 5:22:23 PM5/28/09
to TiddlyWiki
Hello,

I would like to use TiddlyWiki to hold a small dictionary (300-1000
entries, columns 'English', 'French', 'Description')

Do you think that this is possible with TiddlyWiky? Any examples,
plugins, teplates available for this usage ?
Will it be possible to sort by column or does this require a database
solution using PHP + MySQL and not TiddlyWiki?

Many thanks for any hint!

Regards

Frank

Eric Shulman

unread,
May 28, 2009, 6:25:26 PM5/28/09
to TiddlyWiki
> I would like to use TiddlyWiki to hold a small dictionary (300-1000
> entries, columns 'English', 'French', 'Description')
>
> Do you think that this is possible with TiddlyWiky? Any examples,
> plugins, teplates available for this usage ?

You can definitely do this in TiddlyWiki. Here's one basic method:

First, define the dictionary entries, using a separate tiddler for
each entry, where each tiddler contains 'slices' (name:value pairs)
for each language of interest, followed by a 'tiddler section' (a
named *part* of a tiddler) with the definition for that entry...
something like this:

-----------------------------
English: Hello
French: Bon jour
!Definition
This section content can be multiple lines if needed and continues to
the end of the tiddler.
-----------------------------

You can give the tiddler any title you like, as long as it is unique.
I suggest using the same text as the word being defined, using your
primary language (e.g., if English is your primary language, then the
above tiddler would be entitled "Hello", if French is your primary
language, then it would be entitled "Bon jour").

You should also tag the tiddlers to identify them as dictionary
entries so they will be easy to find later on... a simple keyword like
"entry" will do just fine.

Next, dyamically generate the desired tabular output. You can use
http://www.TiddlyTools.com/#InlineJavascriptPlugin
to embed the following script in a tiddler:

<script>
var out=[];
var row='|%0|%1|%2|';
out.push('|English|French|Description|h'); // headings
var tids=store.getTaggedTiddlers('entry');
for (var i=0; i<tids.length; i++) {
var en=store.getTiddlerSlice(tids[i].title,'English');
var fr=store.getTiddlerSlice(tids[i].title,'French');
var d='<<tiddler [['+tids[i].title+'##Description]]>>';
out.push(row.format([en,fr,d]));
}
out.push('|sortable|k'); // table class
return out.join('\n');
</script>

Note use of the 'sortable' class designation in the above table
output. If you install
http://tw.lewcid.org/#TableSortingPlugin
then clicking on a table heading (English, French, or Description),
will sort the table contents by that column. QED.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

Eric Shulman

unread,
May 28, 2009, 9:00:20 PM5/28/09
to TiddlyWiki
errata:

In the example tiddler, this "section heading" line:
!Definition
should be changed to:
!Description
so that when the script invokes this line of code:
  var d='<<tiddler [['+tids[i].title+'##Description]]>>';
it will be able to retrieve and render the desired content.

enjoy,
-e


okido

unread,
May 29, 2009, 11:02:03 AM5/29/09
to TiddlyWiki
Hello Eric,

I did something similar but used datatiddler plugin to store data in
<data> .... </data>.
Is there a particular reason why you use slices ?

Have a nice day, Okido

Eric Shulman

unread,
May 29, 2009, 11:41:45 AM5/29/09
to TiddlyWiki
> I did something similar but used datatiddler plugin to store data in
> <data> .... </data>.
> Is there a particular reason why you use slices ?

Slices (and sections) are native TW syntax. This makes it easier to
share your tiddlers with others without adding any extra plugin
dependencies.

-e

Eric Shulman

unread,
May 29, 2009, 1:29:06 PM5/29/09
to TiddlyWiki
Addendum:

If you want to *hide* the display of the slices or sections (similar
to <data>...</data>), you can enclose them inside TW comment markers,
like this:

/%
name:value
name:value
name:value
%/

and

/%
!sectionname
... multi-line content
goes here...
!end
%/

Note use of "!end" at the end of the section: each section in a
tiddler starts with a line containing '!someName', and stops at the
end of the tiddler OR at a line that contains another '!
someOtherName'. Thus, by putting !end following the section content,
it ensures that the closing comment marker (%/) will not be included
in that section when it is retrieved later on via <<tiddler
TiddlerName##sectionname>>

Also note that, if you are defining several sections in the same
tiddler, you can write it like this:

/%
!sectionA
foo
!sectionB
bar
!sectionC
mumble
!end
%/

enjoy,
-e

Måns

unread,
Jun 1, 2009, 5:24:49 PM6/1/09
to TiddlyWiki
Hi Eric and Okido

Had I known what Eric just told about the use of slices in this thread
- some few months ago - then I wouldn't even have bothered to start
learning how to make tables with fET...
With this simple script I can (almost) rewrite most of my fETs for
datavalues and fields in custom view and edittemplates to simple
slices instead...

My use of the script:
I have a TW for my students synopsisassignments which I share with a
censor...
In each students "tiddlercard" I have a <<notes>> - plugin for notes
and links to the synopsis which I share by link via DropBox.

I almost got a headache trying to figure out the fET for collecting
the data (which I would have to turn into filedvalues first) into a
sortable table. ;-)

Now I use Erics script instead - with slight modifications:

I write sth like this in a students <<notes>>tiddler:
Student: [[Studentname]]
Synopsis:[[Synopsis|http://dl.getdropbox.com/u/SomeName.pdf]]
/%
!Description
Some description
!end
%/

Then I make a tiddler for the collecting script:
<script>
var out=[];
var row='|%0|%1|%2|';
out.push('| Student | Synopsis | Description |h'); // headings
var tids=store.getTaggedTiddlers('Notes');
for (var i=0; i<tids.length; i++) {
var el=store.getTiddlerSlice(tids[i].title,'Student');
var sy=store.getTiddlerSlice(tids[i].title,'Synopsis');
var d='<<tiddler [['+tids[i].title+'##Description]]>>';
out.push(row.format([el,sy,d]));
}
out.push('|sortable|k'); // table class
return out.join('\n');
</script>

!One question:

One thing I miss though - it's numbers for rows and an endcount for
the table...
What would the script look like with numbers for each 'entry' and an
endcount for the table??

YS Måns Mårtensson

Eric Shulman

unread,
Jun 1, 2009, 5:52:08 PM6/1/09
to TiddlyWiki
> One thing I miss though - it's numbers for rows and
> an endcount for the table...
> What would the script look like with numbers for each
> 'entry' and an endcount for the table??

* add another column 'placeholder' to the table row format string:
var row='|%0|%1|%2|%3|';

* add an appropriate heading for the new column:
out.push('| Number | Student | Synopsis | Description |h');

* add the 'loop index' variable, i, to the *beginning*
of the array of values to be formatted:
out.push(row.format([i,el,sy,d]));

* add another line of output following the table,
showing the number of tiddlers that were listed:
out.push('count='+tids.length);

That should do it.

enjoy,
-e

Måns

unread,
Jun 1, 2009, 6:31:05 PM6/1/09
to TiddlyWiki
Thank you Eric

You are great - (with or without your proper headgear on
TiddlyTools ;-))

I have one minor issue with the endcount though..:

The table started with number 0 - so I changed this line:
for (var i=0; i<tids.length; i++)
into
for (var i=1; i<tids.length; i++)

Now the table starts with number 1 instead of zero...

How do I make the endcount take this into consideration (-1) ??

YS Måns Mårtensson

Eric Shulman

unread,
Jun 1, 2009, 6:40:16 PM6/1/09
to TiddlyWiki
> The table started with number 0 - so I changed this line:
> for (var i=0; i<tids.length; i++)
> into
> for (var i=1; i<tids.length; i++)
> Now the table starts with number 1 instead of zero...
> How do I make the endcount take this into consideration (-1) ??

The 'loop index' variable, i, *must* start from 0 because the array of
matched tiddlers starts with 0. Change the starting value to 1 will
result in skipping over the first matched tiddler!

Instead, do this:
out.push(row.format([i+1,el,sy,d]));

-e

Måns

unread,
Jun 1, 2009, 6:46:19 PM6/1/09
to TiddlyWiki
One more (last - I hope) question:
Exclusion:
Can I make the script exclude those tiddlers tagged with entry - but
don't have the !Description slice ??
This way I could get rid of empty rows and only take the tiddlers
with !Description into account...

YS Måns Mårtensson

Måns

unread,
Jun 1, 2009, 6:47:30 PM6/1/09
to TiddlyWiki
Ok -
Thank you very much.

Måns

unread,
Jun 1, 2009, 6:54:28 PM6/1/09
to TiddlyWiki
You can see the resulting table (with empty rows - ) in context here:
http://opgivelser.tiddlyspot.com/index.html#SynopseScript

If I could exclude tiddlers without one of the slices ie !Description
(!Beskrivelse in Danish)
I wouldn't have to change my paralell system for books and articles
(whose notes are also tagged with "NoteArkiv" - but don't have slices
in them)

YS Måns Mårtensson

Måns

unread,
Jun 1, 2009, 7:40:30 PM6/1/09
to TiddlyWiki
Ok - I settle with the option to add another tag and use it instead of
'Notearkiv' ('entry' in the first example) - to get rid of the the
empty rows...
However it would be great to know how to exclude tiddlers without the !
Description -slice in them..
to reduce the amount of different (unique) tags in use...

YS Måns Mårtensson


On Jun 2, 12:40 am, Eric Shulman <elsdes...@gmail.com> wrote:

Eric Shulman

unread,
Jun 1, 2009, 9:02:54 PM6/1/09
to TiddlyWiki
> If I could exclude tiddlers without one of the slices ie !Description
> (!Beskrivelse in Danish)

Add this just inside the 'for' loop:
if (!store.getTiddlerText(tids[i].title+'##Description')) continue;

-e

Måns

unread,
Jun 2, 2009, 2:57:36 AM6/2/09
to TiddlyWiki
Thank you Eric -

I've put it all together like this:
<script>
var out=[];
var row='|%0|%1|%2|%3|';
out.push('| # | Elev | Synopse | Beskrivelse |h'); // headings
var tids=store.getTaggedTiddlers('NoteArkiv');
for (var i=0; i<tids.length; i++){
if (!store.getTiddlerText(tids[i].title+'##Beskrivelse'))
continue;
var el=store.getTiddlerSlice(tids[i].title,'Elev');
var sy=store.getTiddlerSlice(tids[i].title,'Synopse');
var b='<<tiddler [['+tids[i].title+'##Beskrivelse]]>>';
out.push(row.format([i+1,el,sy,b]));
}
out.push('|sortable|k');out.push('i alt ='+tids.length); // table
class
return out.join('\n');
</script>

and it works nicely for getting the tiddlers tagged w 'NoteArkiv' but
don't have the slice '!Beskrivelse'.
However the numbering and endcount don't get affected by the exclusion
- so I'll stick to a unique Tag this time - unless ofcourse, there is
a way to make the numbering work as well.

Thank you for your patience - so far.

YS Måns Mårtensson

Mark S.

unread,
Jun 2, 2009, 9:02:06 AM6/2/09
to TiddlyWiki
On Jun 1, 10:57 pm, Måns <humam...@gmail.com> wrote:
> Thank you Eric -

Yes, I always learn something from following Eric's code!

> However the numbering and endcount don't get affected by the exclusion
> - so I'll stick to a unique Tag this time - unless ofcourse, there is
> a way to make the numbering work as well.

Try this (Note: untested; also term 'i alt' should probably be
something else now ... but I don't read Danish ;-) ) However, if
you're expecting that the same tiddler will always have the same
number ... it probably won't, depending on other tiddlers you add/
delete. :

<script>
var out=[];
var row='|%0|%1|%2|%3|';
var spin = 0 ;
out.push('| # | Elev | Synopse | Beskrivelse |h'); // headings
var tids=store.getTaggedTiddlers('NoteArkiv');
for (var i=0; i<tids.length; i++){
if (!store.getTiddlerText(tids[i].title+'##Beskrivelse'))
continue;
spin++ ;
var el=store.getTiddlerSlice(tids[i].title,'Elev');
var sy=store.getTiddlerSlice(tids[i].title,'Synopse');
var b='<<tiddler [['+tids[i].title+'##Beskrivelse]]>>';
out.push(row.format([spin,el,sy,b]));
}
out.push('|sortable|k');out.push('i alt ='+ spin ); // table

Måns

unread,
Jun 2, 2009, 9:59:20 AM6/2/09
to TiddlyWiki
Thank you for looking into it Mark

- It works exactly as I wanted it to!!
I'm sure that I can use it as a startingpoint/template for many tables
to come :-)
- now I've got the different elements put together..
You can see it in action here:
http://opgivelser.tiddlyspot.com/#[[SynopseScript%20baseret%20p%C3%A5%20NoteArkiv]]

Thanks again Eric and Mark!!

YS Måns Mårtensson

Frank

unread,
Jun 2, 2009, 5:42:25 PM6/2/09
to TiddlyWiki
Eric,

thanks a lot for your great help. Especially the link of the
TableSortPlugin was very helpful for me.

Regards

Frank

***

okido

unread,
Jun 3, 2009, 1:10:09 PM6/3/09
to TiddlyWiki
Hi Mans,

I also replaced FET code by inline js and the tablesort plugin, gives
more speed and less code to load.
I wonder if there is a way to use the formtiddlerplugin and get the
data as slices???

Okido
Reply all
Reply to author
Forward
0 new messages