Invoking scripts via the tiddler macro

50 views
Skip to first unread message

whatever

unread,
Sep 12, 2010, 4:27:17 PM9/12/10
to TiddlyWiki
Hi!
I have a bunch of users and each user requires a dashboard. Each
user's properties are in a user's tiddler and the dashboard is a
separate tiddler. I'm using fET to check if the dashboard exists and
if it doesn't, it displays a button to create the dashboard.
The button consists of the following script:
<script label="New user dashboard" title="Create a new User
Dashboard">
var alwaysTag="user_dashboard";
var alwaysTitle="'s Dashboard";
var title=(tiddler.title+alwaysTitle);
var tags=(alwaysTag);
store.saveTiddler(
title,
title,
"",
config.options.txtUserName,
new Date(),
tags);
story.displayTiddler(null,title);
</script>
The problem is, that the is located in the New Buttons tiddler and
when I invoke it using <<tiddler [New Buttons/
NewUserDashboardSpecific]]>> it produces the title "New Buttons/
NewUserDashboardSpecific's Dashboard" instead of, say, "Jake's
Dashboard". But if I put it in the Jake tiddler, it works fine.
What am I missing?
w

Måns

unread,
Sep 12, 2010, 6:08:35 PM9/12/10
to TiddlyWiki
Hi whatever

I think you'll find the answer in this line:
> var title=(tiddler.title+alwaysTitle);
It seems like it fetches the title from the tiddler from where it is
run (tiddler.title) and adds the alwaysTitle "var alwaysTitle="'s
Dashboard".
Therefore this happens:
> when I invoke it using <<tiddler [New Buttons/
> NewUserDashboardSpecific]]>> it produces the title "New Buttons/
> NewUserDashboardSpecific's Dashboard" instead of, say, "Jake's
> Dashboard". But if I put it in the Jake tiddler, it works fine.

If you want it always to fetch the current users name as title you
must (somehow) replace "tiddler.title" with
"config.options.txtUserName, ".

I would run the script with a substitutionsmarker $1 for "var
title=($1+alwaysTitle);" and try to insert the username by running a
tiddlermacro:
<<tiddler ScriptTiddlerName with:{{config.options.txtUserName}}>> -
However I'm no programmer - and I'm sure someone else, who knows what
he's doing, might change the titlecodeline from "var
title=(tiddler.title+alwaysTitle);" to something like "var
title=(config.options.txtUserName+alwaysTitle);" and make it work...
(I haven't tested it)
Try it out - or wait for a true TwWizard to give you the *correct*
answer.. :-)

Happy hacking Måns Mårtensson

whatever

unread,
Sep 13, 2010, 1:34:57 AM9/13/10
to TiddlyWiki
Hi, Måns.
The problem is, that it's not the user himself who creates the
dashboard, it's his "boss". So when the boss creates a new user, he
has to also create the corresponding dashboard. I've also tried the
stuff you and Eric did in thread
http://groups.google.com/group/tiddlywiki/browse_thread/thread/2822ef3683f3f4cb/9420962722c79303
but it didn't work. Or at least I couldn't get it to work.

w

Måns

unread,
Sep 13, 2010, 4:16:50 AM9/13/10
to TiddlyWiki
Hi whatever

You could try:
<script label="New user dashboard" title="Create a new User
Dashboard">
var alwaysTag="user_dashboard";
var alwaysTitle=prompt("Enter title of XXs DashBoard","s DashBoard");
var title=(alwaysTitle);
var tags=(alwaysTag);
store.saveTiddler(
title,
title,
"",
config.options.txtUserName,
new Date(),
tags);
story.displayTiddler(null,title);
</script>

However this script does overwrite a tiddler with the same title if it
already exists deoesn't it?
Seems a little *dangerous* to me...

Cheers Måns Mårtensson

On 13 Sep., 07:34, whatever <kbrezov...@gmail.com> wrote:
> Hi, Måns.
> The problem is, that it's not the user himself who creates the
> dashboard, it's his "boss". So when the boss creates a new user, he
> has to also create the corresponding dashboard. I've also tried the
> stuff you and Eric did in threadhttp://groups.google.com/group/tiddlywiki/browse_thread/thread/2822ef...

PMario

unread,
Sep 13, 2010, 4:20:31 AM9/13/10
to TiddlyWiki
Have you tried this?
var tid = findContainingTidder();

If new tiddle is in the sidebar, it wont work.
not tested.
-m
http://www.tiddlytools.com/insideTW/#Story.prototype.findContainingTiddler

whatever

unread,
Sep 13, 2010, 8:52:39 AM9/13/10
to TiddlyWiki
Hi!
Måns, the point of the button is to avoid the popup. :D That was what
I had before I tried the above script.
Mario, I get the "ReferenceError: findContainingTidder is not
defined". I tried this:
var tid=findContainingTidder();
var title=(tid+alwaysTitle);

Am I doing it wrong?
Also, I copied the snipped from the link you gave me and it didn't
work. I get a blank.

w

On Sep 13, 10:20 am, PMario <pmari...@gmail.com> wrote:
> Have you tried this?
> var tid = findContainingTidder();
>
> If new tiddle is in the sidebar, it wont work.
> not tested.
> -mhttp://www.tiddlytools.com/insideTW/#Story.prototype.findContainingTi...

PMario

unread,
Sep 13, 2010, 10:24:59 AM9/13/10
to TiddlyWiki
Sorry typos, and to less thinking.
I had an other idea
<<tiddler "ScriptTiddler" with: {{tiddler.title}}>>

in the script tiddler replace this
var title=(tiddler.title+alwaysTitle);
by
var title=("$1"+alwaysTitle);

does it do, what you want?
-m

whatever

unread,
Sep 13, 2010, 1:47:47 PM9/13/10
to TiddlyWiki
It does indeed! Thank you. :D

w

Tobias Beer

unread,
Sep 13, 2010, 1:57:10 PM9/13/10
to TiddlyWiki
Hi whatever,

I believe the problem actually may be that you are creating a local
scope in your fET by putting (tiddler.title) into brackets. Why are
you doing that? Take those brackets out - also for allwaysTag - and
check if ir works.

As for findContainingTiddler it is to be...

var tid=story.findContainingTiddler(place);
//finds the next DOM element up the hierarchy relating to a tiddler

tid=tid?tid.getAttribute('tiddler'):'';
//gets the value of the tiddler attribute of that DOM element or if
none found an empty string

Hope that helped,

Cheers, Tobias.

whatever

unread,
Sep 13, 2010, 2:37:58 PM9/13/10
to TiddlyWiki
Lol!
Removing the brackets didn't help, but using your solution did. Hehe,
not I got two solutions. :D
w
Reply all
Reply to author
Forward
0 new messages