Filter Question: Which Tiddler is Parrent of CurrentTiddler?

There are multiple project tiddlers, which are identified by a category field set to ‘project’.
For instance, I have two project tiddlers named school and work.

Additionally, there are numerous note tiddlers.
A note tiddler has a title that begins with the title of one of these project tiddlers, followed by a ‘/’.
Examples include school/finance, work/costs/jan, work/costs/feb, work/todos, work/salary/lida, work/salary/masoud, etc.

I possess a view template and am in search of an efficient filter to identify the parent of the current tiddler.
What do you propose? I tried lookup with no success!

Does [{!!title}split[/]first[]category[project]] work for you? If the first segment of any tiddler title that includes / is always a “parent” tiddler, you could also omit category[project].

Alternately, if you need the immediate parent, rather than its ultimate ancestor, you could use [{!!title}split[/]butlast[]join[/]].

If this is a pattern you’re using a lot in your template, you could also move your filter of choice into a function. For instance:

\function get.parent() [split[/]first[]]

[{!!title}get.parent[]]

or, depending on how you want to pass parameters,

\function get.parent(tiddler) [<tiddler>split[/]first[]]

[get.parent{!!title}]

or if you’ll only ever need to find the parent of <<currentTiddler>>, you could hard-code it into the function:

\function get.parent() [{!!title}split[/]first[]]

[get.parent[]]
[<get.parent>]
<<get.parent>>

Thank you @etardiff.

The projects are recognized by field category. Their title may have several /. So, we cannot rely on splitting by /.

In that case, I’d try [category[project]] :filter[<..currentTiddler>prefix{!!title}]

1 Like

Great! It works for ViewTemplates!

What do you propose if I had to start with [has[title]].
I am using the filter inside $:/config/FileSystemPaths
(See https://tiddlywiki.com/prerelease/#Customising%20Tiddler%20File%20Naming)
Unfortunately for Filter Run Prefix the <currentTiddler> and <..currentTiddler> seems do not work there or work differently.

I’ve never worked with Node.js, so I’m afraid this may be pushing the limits of my understanding! I think you may need to expand on your specific use-case, though. $:/config/FileSystemPaths seems to be fundamentally concerned with translating tiddler titles into custom file paths… where does <<currentTiddler>> fit into it? Are you trying to replace only the “parent” portion of each tiddler that has a parent category with an alternate prefix?

It would be helpful if you could give us some more specific examples of “parents”, “child” notes, things that follow the slash/based/naming/scheme but shouldn’t be treated as parents or children, and how each of these should look after applying the filter.

Well the situation is a little complex. The real case is theme/plugin development in browser under node.js.
So you have $:/themes/publishername/themename as the parent with a fieldcategory set to theme or plugin.
Children are any tiddler with any complex title but prefixed with a parent!
The duty of filter in $:/config/FileSystemPaths is to save these tiddlers in folder packages-draft within subfolder themename and keep the file structure while ($:/themes/ is removed from title).

This isn’t exactly concise, but does it give you the desired output?

[prefix[$:/plugins]plugintiddlers[]removeprefix[$:/plugins/]]
[prefix[$:/themes]plugintiddlers[]removeprefix[$:/themes/]]
:map[split[/]butfirst[]join[/]addprefix[packages-draft/]]

This does assume that all plugins follow the $:/plugins/publishername/themename format (that is, it won’t work if the publisher name is missing). It would also need to precede any other filters in $:/config/FileSystemPaths to prevent the :map run from being applied to other titles.

You could also replace prefix[$:/plugins] with category[plugin] (or is it plugin-type[plugin] ?), but either way I think you’ll need to use plugintiddlers[].

EDIT: Alternately, if you’re expecting less standardized tiddler titles within a theme/plugin, I’d look at shadowsource, which retrieves the name of the parent plugin specifically.

Thank you! Yes, of course, every line works separately! So, the map is needed for both line!
I use a similar approach, and I was looking to make it simpler and shorter!

This would not work. As the parent is not a plugin/theme yet! They are drafts!

I submitted a ticket and get an early answer from developers. See [IDEA] Resolve inconsistencies between cascade filter run prefix and file system path filters · Issue #8544 · TiddlyWiki/TiddlyWiki5 (github.com)