Consolidate Tiddlers script needed

22 views
Skip to first unread message

Morris Gray

unread,
Nov 11, 2009, 8:53:42 AM11/11/09
to TiddlyWiki
I need to get the contents of several tiddlers and put the whole lot
into another,
This is painfully obviously wrong but perhaps you'll see the logic
behind it,

<script>
var out="";
var append"";
var title="$1";
var tids=store.getTaggedTiddlers("varinested");
var txt=store.getTiddlerText('$1');
for (var t=0; t<tids.length; t++)
append+=txt[t]+"\n";
store.saveTiddler(title,title,append);
return out;
</script>

Can you help?

Morris

FND

unread,
Nov 11, 2009, 9:38:07 AM11/11/09
to tiddl...@googlegroups.com
Just some quick syntactic observations, not sure if that's helpful:

> var append"";

missing a "="

> for (var t=0; t<tids.length; t++)

You might wanna use braces - or at least indentation, if it's just a
single line - to indicate what belongs into that loop.

> append+=txt[t]+"\n";

txt is a string, you treat it as an array (which works, but is probably
not intended - s/txt/tids/ ?)

Also, you might wanna use the array join method instead.

> store.saveTiddler(title,title,append);

You might also wanna supply the fields argument:
http://trac.tiddlywiki.org/browser/Trunk/core/js/TiddlyWiki.js?rev=11166#L309

> var title="$1";

I assume IJSP replaces that with the current tiddler title?
(I don't use IJSP myself.)


-- F.

Morris Gray

unread,
Nov 11, 2009, 4:06:11 PM11/11/09
to TiddlyWiki
On Nov 12, 1:38 am, FND <F...@gmx.net> wrote:
> Just some quick syntactic observations, not sure if that's helpful:

Unfortunately it isn't. I need a bit more detail than that.. Can
anyone else add anything please?

Morris

On Nov 12, 1:38 am, FND <F...@gmx.net> wrote:
> Just some quick syntactic observations, not sure if that's helpful:
>
> > var append"";
>
> missing a "="
>
> > for (var t=0; t<tids.length; t++)
>
> You might wanna use braces - or at least indentation, if it's just a
> single line - to indicate what belongs into that loop.
>
> > append+=txt[t]+"\n";
>
> txt is a string, you treat it as an array (which works, but is probably
> not intended - s/txt/tids/ ?)
>
> Also, you might wanna use the array join method instead.
>
> > store.saveTiddler(title,title,append);
>
> You might also wanna supply the fields argument:http://trac.tiddlywiki.org/browser/Trunk/core/js/TiddlyWiki.js?rev=11...

wolfgang

unread,
Nov 11, 2009, 4:21:42 PM11/11/09
to TiddlyWiki
> > Just some quick syntactic observations, not sure if that's helpful:
>
> Unfortunately it isn't. I need a bit more detail than that.. Can
> anyone else add anything please?
>

Can't help with code really, but Eric's ready solution:

http://www.tiddlytools.com/#EmbedTiddlers

Regards..

Måns

unread,
Nov 11, 2009, 4:31:45 PM11/11/09
to TiddlyWiki
Hi Morris

Don't know if you can use this in your case - but it might give a
clue?:
It takes a hr-separated list of tiddler titles and renders the
tiddlers text in a table.
Use it like this: <<tiddler NameOfTiddlerWithScript with:
NameOfTiddlerWithHrSeparatedList>>


<script>
var out="";
var items=store.getTiddlerText('$1','') .split("\n----\n");
for (var i=0; i<items.length; i++) {
if (i>0 && i/5==Math.floor(i/5)) out += "|\n"; // start a new row
out += "|"+items[i]; // add item to row
}

out += "|\n"; // end last row
return out;
</script>

Regards Måns Mårtensson

Mark S.

unread,
Nov 11, 2009, 5:10:19 PM11/11/09
to TiddlyWiki
I don't know where the dollar sign $1 variable was coming from.
Perhaps you were going to use it as a template?

For this rewrite, I manually put in the name of the target tiddler to
be created. And I changed the tag to something that worked with my
data, so you'll need to change that back. If you see "processed" after
closing out your edit window, you'll know it (or something) worked.

<script>
var out="Processed";
var append=store.getTiddlerText(title);
var title="ActivityArchive";
var tids=store.getTaggedTiddlers("Activity");

for (var t=0; t<tids.length; t++)
append+=store.getTiddlerText(tids[t].title)+"\n";
store.saveTiddler(title,title,append);
return out;
</script>

Be sure that the target tiddler isn't tagged the same as the tiddlers
to be collected, or you might end up with an endless loop!

Mark

Morris Gray

unread,
Nov 11, 2009, 6:53:24 PM11/11/09
to TiddlyWiki
On Nov 12, 8:21 am, wolfgang <pamo...@googlemail.com> wrote:

> Can't help with code really, but Eric's ready solution:
>
> http://www.tiddlytools.com/#EmbedTiddlers

Thanks everyone. Wolfgang this is great but I want to move the content
to another TiddlyWiki. The results of this script can't be moved
because the containing tiddler is just a script.

Here's the latest 'what won't work' I really need help.

Usage
<<tiddler AppendToFile##script with: VariableContent 'VariableContent'
ASectionFile>>

/%
!script
<script label=("$2");>
var out="";
var append="";
var title="$3";
txt=store.getTaggedTiddlers("$1");
for (var t=0; t<tids.length; t++)
append+=txt+"\n";
var out='';
for (var i=0; i<tids.length; i++) out+='<<tiddler [['+tids[i]+']]>\>';
out;
</script>
!end
%/

Morris

Mark S.

unread,
Nov 11, 2009, 7:05:49 PM11/11/09
to TiddlyWiki
Hi Morris,

Did you look at the code I posted? It does work ... at least as
written.

Mark

Morris Gray

unread,
Nov 11, 2009, 7:49:03 PM11/11/09
to TiddlyWiki
On Nov 12, 11:05 am, "Mark S." <throa...@yahoo.com> wrote:
> Hi Morris,
>
> Did you look at the code I posted? It does work ... at least as
> written.

I'm sorry Mark our posts must have crossed in the mail. YES it does
work. I can't thank you enough it was really holding me up as you can
see I was getting in deeper and deeper.

I added a label to make it execute on demand

<script label="Backup">
var out=".....Processed";

The skies are blue again :-)

Morris

Tobias Beer

unread,
Nov 12, 2009, 9:11:25 AM11/12/09
to TiddlyWiki
Hi Mans,

Your scripts doesn't work (here) for a number of reasons.

1) It doesn't output any tiddler text
2) it doesn't properly close the table on any number of hr-separated
tiddlers that is not a multiple of 5
3) if it actually was to output tiddler text, it wouldn't work,
because you would have to ensure that the tiddler-text wouldn't break
the table syntax... so you might have to put <<tiddler
embedThisTidder>> into table cells
4) yet, using <<tiddler SomeTiddler>> to embed its content wouldn't
actually collate the tiddler contents as Morris was looking for

Also...
*you don't need hr's... simple linebreaks will do too, even a
bracketed list



I have been fiddling with your codebits to make something I would
consider a workable solution:

<script>
var i,n,out='',tid,txt;
if('$1'=='$'+'1')return;//no list, no output
var items=store.getTiddlerText('$1') .split('\n');//linebreaks will do
var cols=parseInt('$2');if(isNaN(cols))cols=5;//num cols as 2nd param
n=(parseInt(items.length/cols)+1)*cols;//num cells as multiple of num
cols
for(i=0;i<n;i++){
if(i&&i%cols==0)out+="|\n";//new row
ti=items[i];//title
tid=store.getTiddler(ti);//tiddler
out+='|'+(tid?'<<tiddler [['+ti+']]>>':(ti?'!@@color:red; "'+ti+'"
not found!@@':''));//add item to row
}
out+="|\n";//end last row
return out;
</script>


Assuming script-tiddler is called 'out', you can call it via
<<tiddler out with: tidderWithList##OrListSection 3>>

Where 3 would be the number of columns.

Regards, Tobias.

Tobias Beer

unread,
Nov 12, 2009, 9:16:40 AM11/12/09
to TiddlyWiki
Hi Morris & Mark,

If you also want the titles as headings in the output,
simply replace {{{append+=...}}} with this in the inner loop...

append+="!tids[t].title"+"\n"+store.getTiddlerText(tids[t].title)
+"\n";


Regards, Tobias.

Måns

unread,
Nov 12, 2009, 10:55:41 AM11/12/09
to TiddlyWiki
Great Tobias
Thanks for clearing things up..
I really want to see your script in action - as it has been a thing I
wished to be able to do for a long time and it seems to be able to do
more than my script does :
You also joined the thread where I got my script from Eric
http://tinyurl.com/yzj4kly In action http://tinyurl.com/yjhghpl

When I run your script I get "ReferenceError: items is not defined".
I haven't changed anything in the script (except for repairing googles
linebreaks)-
I even called the script "out" as proposed - and made a another
tiddler with a lineseparated list which gave me the reference error
when run <<tiddler out with: out##OrListSection 3>> -
then I changed the list to a lineseparated list with wikilinks [[]] -
same error -
and finally to a hr-separated list. Same error...

There's no error shown in the "out" tiddler (if it *should* be blank -
that is?) - it's only when I try to run it...

I will try to deliver a MTC - in about an hour - have to set it up
first...

However - if you see that I've made an obvious mistake (I often do -
even if I slow down...) - please reply

YS Måns Mårtensson

Mark S.

unread,
Nov 12, 2009, 12:23:37 PM11/12/09
to TiddlyWiki
Don't know if this is "for real", or a GG line break thing, but this
line:

var items=store.getTiddlerText('$1') .split('\n');//linebreaks will
do

should probably be

var items=store.getTiddlerText('$1').split('\n');//linebreaks will do

HTH
Mark

On Nov 12, 7:55 am, Måns <humam...@gmail.com> wrote:
> Great Tobias
> Thanks for clearing things up..
> I really want to see your script in action - as it has been a thing I
> wished to be able to do for a long time and it seems to be able to do
> more than my script does :
> You also joined the thread where I got my script from Erichttp://tinyurl.com/yzj4klyIn actionhttp://tinyurl.com/yjhghpl

Måns

unread,
Nov 12, 2009, 1:24:17 PM11/12/09
to TiddlyWiki
Hmm - now it seems like there is another parameter I haven't specified
properly:
Error in FF:
TypeError: store.getTiddlerText("TableOutListTest##OrListSection") is
undefined
Error in Google Chrome:
TypeError: Cannot call method 'split' of undefined

Please have a look here: http://tinyurl.com/yjvhlm5

YS Måns Mårtensson


On 12 Nov., 18:23, "Mark S." <throa...@yahoo.com> wrote:
> Don't know if this is "for real", or a GG line break thing, but this
> line:
>
>  var items=store.getTiddlerText('$1') .split('\n');//linebreaks will
> do
>
> should probably be
>
> var items=store.getTiddlerText('$1').split('\n');//linebreaks will do
>
> HTH
> Mark
>
> On Nov 12, 7:55 am, Måns <humam...@gmail.com> wrote:
>
>
>
> > Great Tobias
> > Thanks for clearing things up..
> > I really want to see your script in action - as it has been a thing I
> > wished to be able to do for a long time and it seems to be able to do
> > more than my script does :
> > You also joined the thread where I got my script from Erichttp://tinyurl.com/yzj4klyInactionhttp://tinyurl.com/yjhghpl

Mark S.

unread,
Nov 12, 2009, 6:41:44 PM11/12/09
to TiddlyWiki
As I posted before, this line isn't right:

var items=store.getTiddlerText('$1') .split('\n');//linebreaks will do

There is a space between the right parenthesis and the period here:

"('$1') ."

That space must go!

HTH
Mark

Måns

unread,
Nov 12, 2009, 7:07:40 PM11/12/09
to TiddlyWiki
Hi Mark

I'm sorry to be such a "problemspammer" - (don't know a good word for
it - ) but i *did* try to remove the space - and had the exact same
errormessages in FF and GC...

Now I've saved the changes and you can see it online http://tinyurl.com/yjvhlm5

YS Måns Mårtensson

Mark S.

unread,
Nov 12, 2009, 9:43:00 PM11/12/09
to TiddlyWiki
Hi Måns,

"problemspammer" ... cute

Your next problem is that there is no OrListSection
inside of TableOutListTest.

When I take out the OrListSection specification, it draws a table.
However, all the cells claim the corresponding tiddler can't be found.
Probably because they are all system tiddlers. But it will find and
display non-system tiddlers.

I'm not sure I understand why you would want to put all these tiddlers
into a table ... since the first line feed will break the table
formatting.


Mark

On Nov 12, 4:07 pm, Måns <humam...@gmail.com> wrote:
> Hi Mark
>
> I'm sorry to be such a "problemspammer" - (don't know a good word for
> it - ) but i *did* try to remove the space - and had the exact same
> errormessages in FF and GC...
>
> Now I've saved the changes and you can see it onlinehttp://tinyurl.com/yjvhlm5

Måns

unread,
Nov 13, 2009, 3:34:57 AM11/13/09
to TiddlyWiki
Hi Mark

Now it works!!!
Nothing is broken even if the tiddler has several linebreaks and it
fetches systemtiddlers as well!!
Thanks for helping me out explaining the missing section (in the
listTiddler) and extra space..
The sectionreference was just an example showing that you *can* fetch
a section if it's there...

I had to specify colums *and* rows to make it work (hence the $1*and*
$2)...
<<tiddler out with: TableOutListTest 3 5>>

This is an awesome script that Tobias made - and it surely will find
it's use...
Thank you very much Tobias - this is pure magic from a true
TWWizard ;-)

See it in action here: http://tinyurl.com/tableout

YS Måns Mårtensson

Måns

unread,
Nov 13, 2009, 3:56:43 AM11/13/09
to TiddlyWiki
Castles in the air - or just a new scriptvariant approximating Erics
GridPlugin?

Next obvious step would be to let it fetch a list produced by
javascript (or fET) integrated in the same tiddler in a ##section
where you might have interactive controls (prompts?) for collecting
tiddlers based on tags and/or fields and an option to sort
(TableSortingPlugin?).

If you added an option to edit each tiddler directly in the table -
then you would have something similar to Erics fabulous GridPlugin
with the advantage of beeing able to set number of columns and rows
*and* if you add an optional section (could be chosen with a
"selectsection or tiddlerlist button") you could create new tiddlers
specified in the tiddlerlist (or section) directly in the
tableouttiddler -

Don't know if this makes any sense?
Anyway I think the script is very usable as it is...

regards Måns Mårtensson

Tobias Beer

unread,
Nov 13, 2009, 11:49:04 AM11/13/09
to TiddlyWiki
Hi Mans and Mark,

I never thought this would make so many circles...
And next time, I will DEFINETELY use a pastebin ;-)
Here's what should have been in one to begin with:
http://pastebin.com/f34891c8c

To cut your ideas short... once you envision any particular usecase
based on this
and you're stuck, I'm sure we're going to get there...
and learn ever more stuff in magic tw land.

Tobias.
Reply all
Reply to author
Forward
0 new messages