How to get evaluation to work in tiddler macro?

20 views
Skip to first unread message

Mark S.

unread,
Jul 5, 2009, 4:15:21 PM7/5/09
to TiddlyWiki
I have the ExternalTiddlerPlugin installed. I'm trying to get the
tiddler macro to evaluate the contents of a separate tiddler in order
to determine what tiddler will be imported. Here's what I have tried
so far:

<<tiddler {{"return store.getTiddlerSlice('PagePick','page')+'#3'
"}} >>
<<tiddler {{"store.getTiddlerSlice('PagePick','page')+'#3' ; "}} >>
<<tiddler [[PagePick::page]]#3 >>

I've tried other versions. None of these have worked so far. As a
check, I ran the script:

<script>
return store.getTiddlerSlice('PagePick','page')+'#3' ;
</script>

and it returns the correct response:
killthis.html#3

And yes, "killthis.html" exists in the same directory, and has a
tiddler called "3".

In fact, I can do exactly what I want if I construct the macro on the
fly like:

<script>
return "<<tiddler " + store.getTiddlerSlice('PagePick','page')+'#3' +
" >>" ;
</script>

But somehow that seems clumsier than it ought to be.

Thanks in advance,
Mark

Eric Shulman

unread,
Jul 5, 2009, 9:03:03 PM7/5/09
to TiddlyWiki
> tiddler macro to evaluate the contents of a separate tiddler in order
> to determine what tiddler will be imported
>  <<tiddler  {{"store.getTiddlerSlice('PagePick','page')+'#3' ; "}} >>

You were very close!

The use of the trailing '' in the above code snippet forces the result
to be a blank string so that the computed parameter can evaluated
*without* producing any macro output, as a way to invoke tiny bits of
javascript without using InlineJavascriptPlugin. However, for your
purposes, you *do* want to produce output from the <<tiddler>> macro,
so you need to get rid of the trailing '' in order for the correct
param value to be applied. Thus:

<<tiddler {{"store.getTiddlerSlice('PagePick','page')+'#3'}} >>

enjoy,
-e

Eric Shulman

unread,
Jul 5, 2009, 9:04:37 PM7/5/09
to TiddlyWiki
errata:

there was an extra leading quote that needed to be removed as well...
thus:

<<tiddler  {{store.getTiddlerSlice('PagePick','page')+'#3'}}>>

-e

Mark S.

unread,
Jul 6, 2009, 1:19:10 AM7/6/09
to TiddlyWiki
Hi Eric,

Thanks for the help! I think what you're saying is that if there is
any space in the input scriptlet, then the parser will think you are
starting a new parameter and discard the previous one as incomplete.
Or?

Now that I have it working, I realize that the ExternalTiddlerPlugin
doesn't seem to allow me to dive down one directory, with a relative
path like this:

<<tiddler directory/targetfile.html#1 >>

or with any other path I've tried. Is this a typical safety protocol,
or is there some formulation of path that will allow this to happen?

Many thanks again!
Mark
Reply all
Reply to author
Forward
0 new messages