On Jan 18, 4:36 am, Clark Kogan <[email protected]> wrote:
> Hello,
> I was using the following code in an inline jscript function:
>
> tid = story.getTiddler(tidname);
> tidtitle = tid.title;
>
> If I put in a tidname that does not exist, story.getTiddler will still
> return an object.

It should set tid to null if the tiddler doesn't exist.

> However, when I ask for the title (in line 2), it
> gives an error that tid is null. I was wondering how I can
> programatically determine whether I am getting a nonempty tiddler
> before I run line 2.

To test whether a tiddler has been returned before performing the 2nd
line you can use an if statement. Your code would become
var tid = story.getTiddler(tidname);
if(tid) {
    tidtitle = tid.title;
}

Alternatively, you can use the tiddlerExists method before retrieving
the tiddler. This can be used by passing it the tiddler name as a
parameter and it with return true or false depending on whether it
exists. E.g.
if(store.tiddlerExists(tidname)) {
    var tid = store.getTiddler(tidname);
    var tidtitle = tid.title;
}

Hope that helps,

Colm

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.

Reply via email to