Don't use ID to retrieve tiddler name

16 views
Skip to first unread message

colmjude

unread,
Oct 27, 2011, 10:33:12 AM10/27/11
to TiddlyWikiDev
Hi All,

This is just a quick warning for all plugin authors.
It used to be quite common practice to use a displayed tiddler's ID
attr to get the title of the tiddler. Code like this was often used in
a macro handler function:
...
var tidEl = story.findContainingTiddler(place);
var title = tidEl.id.substr(7);
...

If you had a tiddler titled "A Tiddler Title" then the id would have
been "tiddlerA Tiddler Title", hence stripping the first 7 chars left
you with the title.

This is NO longer the case, meaning you should no longer use this
pattern. Plus plugins that use this pattern will no longer work in
more recent versions of TW.

ID attributes are now being marked up correctly so instead of it being
"tiddlerA Tiddler Title" it is "tiddlerA_Tiddler_Title".

However the displayed tiddler does have a tiddler attribute that
contains an unaltered tiddler title which you can use instead. For
example:
...
var tidEl = story.findContainingTiddler(place);
var title = jQuery(tidEl).attr('tiddler');
...

Hope that helps,

Colm

Eric Shulman

unread,
Oct 27, 2011, 11:38:04 PM10/27/11
to TiddlyWikiDev
> This is just a quick warning for all plugin authors.
> It used to be quite common practice to use a displayed tiddler's ID
> attr to get the title of the tiddler. Code like this was often used in
> a macro handler function:

> var tidEl = story.findContainingTiddler(place);
> var title = tidEl.id.substr(7);


There's also the inverse usage, where a tiddler title is used to find
a displayed tiddler element, like this:

var tidEl=document.getElementById("tiddler"+title); OR
var tidEl=document.getElementById(story.idPrefix+title);

which should be replaced with
var tidEl=story.getTiddler(title);

Note: As of a year ago (11/30/10) *all* TiddlyTools plugins are using
the correct TWCore API calls to retrieve and reference rendered
tiddler elements. Of course, lots of documents continue to use older
revisions of my plugins, so this problem may still occur when people
migrate those documents to the current TWCore without also updating
their plugins to get the latest revisions from TiddlyTools.com

-e
Reply all
Reply to author
Forward
0 new messages