> I'd like to use RelatedTiddlersPlugin in a manner similar to
> SectionLinksPlugin.
You mean like the <<sectionTOC>> macro (which automatically generates
a tree of links to sections *within* the current tiddler)... but
showing a tree of TiddlyLinks to related tiddlers instead of sections?
> A primer would be appreciated on how to achieve the following
> functionality (I suspect most of it can be had using the provided
> API?)
The Usage section of the plugin documentation says:
-----------------------------
The plugin also defines two functions that can be called externally
(from other plugins or scripts) to generate and retrieve either a list
of links or a formatted "tree view":
var list=config.macros.relatedTiddlers.getList
(start,exclude,callback);
var tree=config.macros.relatedTiddlers.getTree
(start,exclude,callback);
These functions accept parameters to specify the starting tiddler, and
a list of tiddlers to exclude, as well as an optional callback
function that takes any specified tiddler as input and returns a
custom-defined array of links related to that tiddler:
var list=callback(tiddler);
Use of the callback function enables you to generate an alternative
list/tree, based on application-specific data (such tiddler references
contained in tags or custom fields), rather than using the default
"links" list.
-----------------------------
In addition, the Examples section of the plugin documentation, shows
some sample inline scripting to invoke the plugin-defined function.
With a few changes, this script will do exactly what you want:
-----------------------------
<script>
var here=story.findContainingTiddler(place);
var target=jQuery('#'+
here.id+' .relatedTiddlers')[0];
var start=here.getAttribute('tiddler');
var exclude=config.options.txtRelatedTiddlersExclude.readBracketedList
();
var count=config.macros.relatedTiddlers.getList
(start,exclude).length;
if (count>1) {
var tree=config.macros.relatedTiddlers.getTree(start,exclude);
if (target) target.style.display='inline';
wikify(tree,target||place);
}
</script>
-----------------------------
This will generate the desired tree output, starting from the current
tiddler.title and then uses a jQuery() call to locate and render the
desired 'target' element (by matching the .relatedTiddlers classname)
within the currently rendered tiddler. Note: if no such target
element is found, the output is written directly into the current
'place' (i.e., the location where the script itself is being
rendered).
To invoke this script from within your ViewTemplate (so the tree is
automatically rendered for each tiddler), first put it into a separate
tiddler (e.g., [[ShowRelatedTiddlers]]), and then write the following
in the template:
-----------------------------
<span class='relatedTiddlers small' style='display:none'
macro='tiddler ShowRelatedTiddlers'>
<b>Related:</b><br>
</span>
-----------------------------
This both creates the target element *and* invokes the script that
renders the tree into it.
enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios