Tinderbox: getting information from other notes
Let’s take a moment to look at one of the tricky corners of Tinderbox. How can one note find out about its neighbors, or about other notes in your document?
Usually, a Tinderbox note is chiefly concerned with what it says and with its own properties. But sometimes, a note needs information from other notes – either for exporting that information, or to use in an action. Collections of notes, each with their own simple and small actions, can work together to do make your notes organize themselves in surprisingly effective ways.
When might a note be interested in other notes? Let’s imagine some examples:
- If a note is a task in a list of tasks, it might highlight itself if it’s the first task in the list.
- If a note needs to use a Web service – Google Maps, say – it needs to know about the note where you store your user key.
- If a container represents a section of your new book, it might be interested in knowing when you most recently updated something in that section.
Let’s look at the mechanics. For example,
$Text
is the text of this note. We can export it:
^value($Text)
or we can test it
if( $Text.empty ) { ... do something ... }
or we can set it.
$Text="....something -- perhaps results from another program...";
But suppose we’re interested in the text of some other note. We might, for example, want the text of our container:
$Text(parent)
Or, we might want the text of a particular note whose location we know
$Text(/configuration/weblog/credentials)
If we know that we have a child note called "references", then
$Text(references)
will look first for that child note. If there isn’t a child named “references”, we’ll look for the first note in the document that is named “references”.
We can combine these designators, too.
$Text(parent(parent))
gives us the text of the parent of our parent.
$Text(nextSibling(parent))
gives us the younger sibling of our parent – our “uncle”.
$Text(references(parent))
gives us the note named “references” that is a child of our parent.