getTiddlerText

200 views
Skip to first unread message

tejjyid

unread,
Jun 22, 2012, 2:34:34 AM6/22/12
to tiddl...@googlegroups.com
A couple of things - maybe they should be separated:

I was wanting to create a <<tabs>> based structure, where one tab would show a base text, and other tabs would show (programmatic) annotations of this base. I thought each tab could point to a macro with a parameter string which included the original base text.
So I tried <<myMacro {{tiddler.getTiddlerText(myTiddler)}}>> following http://oldwiki.tiddlywiki.org/wiki/Dev:Custom_Macros, and then I looked at http://tiddlywiki.tiddlyspace.com/#TiddlyWiki.prototype.getTiddlerText, which looked like an alternative plan, but neither worked. It seems that the string is never evaluated before being passed to the macro.

So the 2 things are:

1.) Why are the getTiddlerText methods(?) not working, and
2.) Is there a pre-existing template/macro/script for doing what I want to do?

Clarifications on request :-)

Thanks in anticipation
Andrew

whatever

unread,
Jun 22, 2012, 4:10:43 AM6/22/12
to TiddlyWiki
Hi!

the myMacro is only an example. You actually need to write your own
macro in javascript.
To get the tiddler text, you need to use the following:
var text = store.getTiddlerText("YourTiddlerName");

Then you can use the text variable further on. Check out a random
tiddlywiki plugin to see how the macros are declared.

Perhaps some other javascript guru can write a more detailed
explanation.

As an alternative plan, however, perhaps you can use the
forEachTiddlerPlugin (1) and simple transclusions:

In tiddler called "Lists" (or whatever you wanna call it), put:
!Base
<<forEachTiddler where 'tiddler.tags.contains("myTag")'
write '"<<tiddler [["+tiddler.text+"##Base]]>\>\n"'>>
!Annotations
<<forEachTiddler where 'tiddler.tags.contains("myTag")'
write '"<<tiddler [["+tiddler.text+"##Annotations]]>\>\n"'>>
!Macro
<<forEachTiddler where 'tiddler.tags.contains("myTag")'
write '"<<tiddler [["+tiddler.text+"##Macro]]>\>\n"'>>

In another tiddler, put this:
<<tabs txtMyTabs "Base" "Base" "List##Base" "Annotations"
"Annotations" "List##Annotations" "Macro" "Macro" "List##Macro">>

That way you have three tabs and each contains certain content. If I
understood correctly what you wanted, of course. :D And I'm sure there
are other solutions.

(1) http://tiddlywiki.abego-software.de/#ForEachTiddlerPlugin

w

On Jun 22, 8:34 am, tejjyid <andrew.x.w...@gmail.com> wrote:
> A couple of things - maybe they should be separated:
>
> I was wanting to create a <<tabs>> based structure, where one tab would
> show a base text, and other tabs would show (programmatic) annotations of
> this base. I thought each tab could point to a macro with a parameter
> string which included the original base text.
> So I tried <<myMacro {{tiddler.getTiddlerText(myTiddler)}}>> followinghttp://oldwiki.tiddlywiki.org/wiki/Dev:Custom_Macros, and then I looked athttp://tiddlywiki.tiddlyspace.com/#TiddlyWiki.prototype.getTiddlerText,

tejjyid

unread,
Jun 22, 2012, 8:07:45 PM6/22/12
to tiddl...@googlegroups.com
Thanks, I'll look into this.

I did realise that the myMacro was only an example :) - the problem was/is that I should be able to pass data to the macro, and the {{...}} should cause the included expression to be evaluated before being passed as data to the macro. So then, the store.getTiddlerText("YourTiddlerName") should be evaluated and the text the passed off to myMacro.

So, if that understanding is correct, I had 2 apparent problems:
1.) should I use tiddler.getTiddlerText (as per wiki), or store.getTiddlerText (as per tiddlySpace FAQ)? From your reply I can see that you favour the latter, so I'll persist with that
2.) no apparent evaluation was occurring inside the {{...}}. Again, using your reply I can seen an alternative, but I'm still a little curious as to what's happening in my initial situation.

Anyway, on the cat-skinning principle, I'll wander off and try your suggestion(s) & let you know how it goes.

Thanks again, Andrew

PMario

unread,
Jun 23, 2012, 4:45:44 AM6/23/12
to TiddlyWiki
Hi Andrew,
I'm not sure, if you use TiddlySpace or not. but ...
Evaluated macro parameters are deactivated by default with
TiddlySpace, due to security concerns.
-m

tejjyid

unread,
Jun 23, 2012, 8:18:32 AM6/23/12
to tiddl...@googlegroups.com
Ahhh - well, I am using TiddlySpace - thx.

So I thought instead I'd just use the "myTiddlerName" as the parameter and then use the getTiddlerText inside the macro.
Now I'm getting TypeError tiddler.fields is undefined whenever I execute the macro.

Anyway, I'll keep playing around, all this trial-and-error is very e
ducational

Andrew

tejjyid

unread,
Jun 24, 2012, 4:02:40 AM6/24/12
to tiddl...@googlegroups.com
Right. Final report.
I worked out the syntax error & passing the tiddler name into the macro is perfectly adequate.

BUT, note to others, the example code in the OLD wiki (How to write a macro), which uses "tiddler.getTiddlerText" doesn't work, 'cos there is no such function. When we update the FAQ in the new TWSpace format we need to use the "store.getTiddlerText" method.

whatever, I ended up not trying your solution, but I can see myself getting back to it.

Thanks all

PMario

unread,
Jun 24, 2012, 1:32:46 PM6/24/12
to TiddlyWiki
Andrew,
I did a little "hello world" [1] how to, that shows 3 different
macros. If you start in the main menue, top to bottom, they get more
"features". The code is commented, so it should be possible to get,
how they are ment.

You can include the helloworld space into one of your spaces and play
with the macros. If you mess them up, just rename them and you have a
fresh start using the examples :)

you should have FireBug or the Chrome dev tools at hand for debugging.

have fun!
mario

[1] http://helloworld.tiddlyspace.com/

tejjyid

unread,
Jun 29, 2012, 6:56:40 AM6/29/12
to tiddl...@googlegroups.com
Thanks mate, I'm onto it.
Reply all
Reply to author
Forward
0 new messages