How to list ^childLinks^ for a different note

I just tripped up on this issue and in reminding myself of the solution, I realised it is obvious until you know. Thus this tip!

So, I wanted this aTbRef page to list links to the children of this page.

^childLinks^ seems the obvious solution. But, it only links this note’s children, i.e. those of the note being exported. In this case we want them from a different note.

However, ^include()^ allows us to include the content of a specified note either using its default export temple (that note’s $HTMLExportTemplate) or via a user-specified template. How does this help? Well, we know the target note to use, but clearly we don’t want in insert a full HTML page code into another HTML page. But, if we use a custom template that returns only a list of links to its children we have what we need and we know ^childLinks^ will give us the template code we need…

So, we add a new HTML export template to the document. I called mine “child-links”. It contains only this code:

^childLinks^

Thus when a note is called using that template, all ^include()^ will return is the target note’s children as an HTML-formatted list of links. Tada!

So the note needing the list now has this code at the end of its $Text:

^include(/A Tinderbox Reference File/Objects & Concepts/Concepts/Actions/Functions,"child-links")^

with the result seen here. The target note is cited as a full path (the $Name might not be unique) so the path is not quoted to help indicate it is a literal path and not a $Name value needing its path calculated. conversely, the custom template’s name is (deliberately) unique so I use just its $Name value in double quotes.

You might say it seems like an effort. Why not simply manually add a list of Text links into the $Text of the latter note? You could, but what if the target list changes. In a constantly-updated doc like aTbRef, that happens all the time and, to my embarrassment, it is easy to add a new page and find it not listed as a link in expected places. This method takes care of that.

Be aware that ^childLinks^ lists the source’s children in $OutlineOrder. If you need a different order, or to only include/exclude some children, that is not possible but note via this simple template. There are other approaches involving more code but that’s outside the scope of this tip.

†. As we often like to nest templates and use explanatory titles, their full $Path can get quite long. Therefore, for templates especially, I like to give export template deliberately unique titles allowing me to just quote the $Name value when referencing them. This is aspect of quoting names but not paths but quoting titles is a bonus mini-tip. See more.

7 Likes