Creating a recursive macro

I am also interested on display the path from the root to a particular leaf, but parent field is a list.
Ideas on how how to achieve Example2 result?


Example1:
tiddlerC parent field = tiddlerB
tiddlerB parent field = tiddlerA

<<hierarchy “tiddlerC”>>
Result:
tiddlerA::tiddlerB::tiddlerC


Example2:
tiddlerC parent field = [[tiddlerB]] [[tiddler2]]
tiddlerB parent field = [[tiddlerA]]
tiddler2 parent field = [[tiddler1]]

<<hierarchy “tiddlerC”>>
Result:
[[tiddlerA::tiddlerB::tiddlerC]] [[tiddler1::tiddler2::tiddlerC]]


Thanks!

At a high level on the current tiddler list the parent field then for each tiddler, there in, call a macro, that lists each of those, calling itself.

  • if you can trust there are No loops in the heirachy this can be quite simple.
  • if you can share some test data in a json file we can drop on tiddlywiki.com we can write a solution for you.
    • use @pmario TocP macro of you want

I do trust that there are no loops in the heirachy.
I guess a minor syntax modification will make it work but it’s far from obvious at my current skill level.

This is the functionality i want to achieve:
recursive

The purpose is an automatic sorting of flashcard decks from the tiddlyremember plugin.
In this example, a card created in tiddler AAA will appear in the Anki deck A::AA::AAA

1 Like

You may want to have a closer look at my trails-plugin, which allows you to create breadcrumbs and trails.

https://wikilabs.github.io/#trails

1 Like

I did checked the trails-plugin, the problem is that on breadcrumbs you must specify the start tiddler.
I want to render the macro in every tiddler by tagging it as $:/tags/Macro, specifying a start tiddler on every tiddler seems too much work.

I am also exploring the relink pluggin, which might work…

Only the stop-tiddler is required – Every other parameter is optional

See: BC & Trails — Breadcrumbs & Trails Visualize your Context

1 Like

One way is to have the start tiddler = <<currentTiddler>> but the bread crumbs solution finds where current tiddler is within its list.

$:/tags/Macro allows the defined macro to be called anywhere, see also the new global tags, but to place it on every tiddler you are better using a tiddler tagged $:/tags/ViewTemplate and putting your “macro call” in that. It will then appear on every tiddler, and you use currentTiddler.

  • Use a list-before or list-after field to ensure where it comes in the $:/tags/ViewTemplate list to control where you see it.
  • Or in the $:/tags/ViewTemplate tag pill drag and drop to reorder.

Alternatively to $:/tags/ViewTemplate you can use SystemTag: $:/tags/ViewTemplate/Subtitle to place it in the subtitle.

It is also a good idea to wrap it in a condition

<$list filter="[all[current]!is[system]]" variable=nul>
<<your macro>>
</$list>
  • With the above it will only appear on non-system tiddlers.
  • Note the variable is set to nul so it does not change the current tiddler.
1 Like

By reverse engineering your work I came up with this solution that does exactly what I needed:

\define AnkiPath()
	<$let
		next={{{ [<currentTiddler>get[parent]enlist-input[]] :else[[TW]] }}}
	>
			<$list filter="[<next>!match[TW]]">
<<AnkiPath>>::<<currentTiddler>>
			</$list>
	</$let>
\end

\define Anki()
<<AnkiPath>>::<<currentTiddler>>
\end

By calling <<Anki>> inside tiddler “AAA” I do get trail A::AA::AAA

I am now trying to readapt the code so the same output is achieved through functions instead of macros, by performing something like this {{{ [<currentTiddler>function[Anki]] }}}

Given that Fourth Tiddler’s parent is Third Tiddler, and Third Tiddler’s parent is Second Tiddler, and so on…
How should the following filter be modified so it outputs the string
FirstTidder::Second Tiddler::ThirdTiddler::Draft of Fourth Tiddler
instead of the following?

This is my closest ugly approach so far, but recursive solutions are welcome too.

*Code for copy-pasting:

{{{  
[<currentTiddler>get[parent]enlist-input[]]:map[get[parent]enlist-input[]]
[<currentTiddler>get[parent]enlist-input[]]:map[get[parent]enlist-input[]] 
[<currentTiddler>get[parent]enlist-input[]]
[<currentTiddler>]
}}}

Sorry, been so involved in other things that I haven’t had time to look at this.

The JS I mentioned earlier in this topic, might be a good start at what you’re looking for. But I haven’t tried to turn this into TW code. It’s not trivial, but also shouldn’t be terribly hard… at least if you’re willing to do it as JS. Wikitext might be substantially more difficult.

This is what you was looking for:

\function ankifunction()
[<currentTiddler>get[parent]enlist-input[]] :map[get[parent]enlist-input[]]
[<currentTiddler>get[parent]enlist-input[]] :map[get[parent]enlist-input[]]
[<currentTiddler>get[parent]enlist-input[]
[<currentTiddler>]
\end


{{{    [all[]function[ankipath]]:and[join[::]addprefix[TW::]search-replace:gi[::::],[::]search-replace:gi[::::],[::]search-replace:gi[::::],[::]]     }}}