I’ve been thinking about a similar problem using the TOC macro.
I think my overall strategy will be to use the kin plugin to determine all the tiddlers in the tree. Then apply a search criteria to find tiddlers that match. Then walk back up the tree for each of those tiddlers until reaching the root. Actually, the kin plugin will let you walk up a tree as well, so maybe that step can be simplified.
In my case though, I hope to be using the selective expanded mode, and open the branches that are pathways to the tiddler matching the criteria.
Thank you Mark.
Actually I use this for navigation! So, it can be used with TOC also!
I am not familiar with kin plugin but will have a look to see how it works!
This is a bit rough, but should be tweakable to what you need if you don’t want to use the plugin @atronoush. It’s just a general recursive loop I tweaked from a post on “recursive” in Google Groups.
Note that I “lazily” used the # character as a delimiter, so if you use that in your titles, change it to another character. Note the child-tiddler is the name of the tiddler at the end of the chain so-to-speak.
There will be new opportunities in the prerelease 5.2.0 using the counter variable. However as @stobot points out others (and I) have published extensively on recursive solutions on GG. Basically when you start to “iterate hierarchies” (other than using the TOC macros) it really pays to make your own nested or recursive macros.
Clever solution @stobot
There is only one issue, if a child tiddler has more than one tag, how the code will work?
I think it should see which tag returns to parent or grand parent root
Good to hear @atronoush - yeah I was targeting more of a “teach a man to fish” solution to append to the “give a man a fish” solution that came from the plugins that were already suggested. I think in a forum like this, if you can give both, then that’s the best. I’ve learned most of what I know from people like @EricShulman and others giving really detailed answers with mock code so I try to pay that forward.
To take it slightly further per the “gotchas” mentioned above, I’ll say there are a few relatively easy ways to enhance the core/base pattern I posted. I’ll point out just for reference:
If you have extra tags and you know what they are:
For example, if all of those tiddlers in the hierarchy were also “People” and therefore also had a “People” tag, then you could add a !tag[People] into the filter in the right place (right after the tags[] part of the parent-loop macro) to ignore those.
If you will have multiple ways of getting to the same place due to just a jagged hierarchy:
If you happen to not really show all of the ways to get from the top to the bottom, you could just arbitrarily pick one by adding a limit[1] to the same spot (right after the tags[] part of the parent-loop macro). This way it still “works” in a way in that you still get a hierarchy, it’s just not all of the possible hierarchy paths. That might be fine. If you needed all, you’d want to think about how you’d want that returned. Happy to help brainstorm if that’s the case.
If you’d rather use fields instead of tags:
You’d have to change a few places, but the pattern would be the same. For instance, if you had a field for each of these called myparent for instance and it only stored a single possible parent, then you’d only need to change the tags[] to get[myparent] in the parent-loop macro and it should work the same I think.
I am in the process of responding to the original post in full and taking account of the issues that already exist.
Basically its a simpler rewrite of the TOC macros based on new methods and the counter widget of 5.2.0. It currently includes the ability to feed it different filters to determine membership and order.
I intend to include the ability for nodes to specify their own filter for their children.
Then this could be used to search for a specific item eg; 0.1.5.5. then link to the tiddler. You can see how this satisfies the “Location of Item”.
I have attached by work in progress, warning it is only that. toc-positions.json (1.7 KB)
Later I will add different expandable and tabbed features.