Inherit or pass on Metadata Values from Active File when creating New File

What I’m trying to do

Hi community,
I have a question which I haven’t been able to solve on my own so I’d highly appreciate any hints/feedback/suggestions whatsoever:

My starting point is Christian B.B. Houmann’s Project & Goal Workflow which basically uses his Quickadd plugin to let you easily create new (auto-tracked) Goals and then create and track corresponding Projects that help achieve said Goals. You are also able to view and manage them via Dashboards/Kanban Boards.
I already set this up and it’s working fine, however, I want to tweak it a little bit to fit my use-case, which is mainly academic writing:

Let’s say I have already created “Goal 1” and a “Project 1” that belongs to the Goal (because it has the frontmatter “tag: project” and the Inline field “Goal:: Goal 1”)

Now I would love to find a way that let’s me refactor new Notes from “Project 1” (probably using Refactor plugin) as brother- or sub-projects that are linked to the same Goal, or even inherit all t

Things I have tried

This “inheritance of metadata” is what my question really is about:
I’ve thought of a few ways that might somehow work, but I haven’t figured out which one REALLY works like I need it to.

  • The refactor plugin:

    • lets you import selected content into a new note, but I’m not planning on selecting the metadata too - just the content to refactor.
    • lets you create a template that inserts the old {{title}} into the new note
  • The Dataview plugin:

    • lets you create inline-queries to display metadata-values from a selected file and key: = [[Project1]].Goal displays as [[Goal1]] in live-preview.
      • However, I can’t access this “dynamic” value from the Dashboard/Kanban-views or generally other dv-queries.
        • → Is there a way to turn this “dynamic” value into a static one (and “burn it in”, so to speak) ?
  • the Templater plugin:

    • my first hope was that Templater would be able to “burn it in” for me, but <%tp.frontmatter.<variable_name>%> let’s you only access frontmatter variables from the current file. However I need to access the frontmatter + Inline variables from another (= the previous) file…
    • from what I’ve read so far, it seems I would have to use some type of JS magic, or at least find a way to access the dataviewAPI from within templater, but since I’m not a coder I won’t be able to do this on my own…
  • The QuickAdd Plugin:

    • I’m guessing one could probably do the whole workflow within QuickAdd as it let’s you create whole sequences of various actions, which are then automatically performed.
      • e.g. I could create a following macro-sequence:
          1. trigger Refactor-Plugin to create new file from selected content
          1. insert <% templater functions %> or {{QuickAdd: Values}}
          1. trigger/replace those to end up with inherited metadata.
      • However, I’m not really sure how to properly setup the steps 2 and 3.
  • Has anyone built a similar system and can share how they’ve achieved it?

  • Any general tips on “Metadata Inheritance”?

    • I know Obsidian is not primarily a database, but seeing what other people have created with it, I’m sure there must be a way to do achieve this ‘relatively simple’ operation of inheriting metadata.

I’m open to all possible approaches of figuring this out and any help is much appreciated, thank you!
Kind regards,
Leo

It seems like the way forward would be to use Templater. Then you would trigger the template in the “previous” file, gather all the necessary metadata, and the content to extract or use as base in the new file.

Then the template would create the new file with either an appropriate template or your generated content, and you can leave a link in the active (aka “previous”) file.

This way you would have full access to both files, and can choose whether to (or when) to shift focus to the new file. Or potentially just create it in the background, and keep editing the active file.

Ok, thanks for your response!!

I think I understand everything you wrote, except for the part where I ‘gather all the necessary metadata’… How would you go about ‘gathering’ it?

Sorry it took me so long, but here is a template to trigger your creative juices:

<%*
const dv = this.app.plugins.plugins["dataview"].api

const curr = tp.config.target_file
const dvCurr = dv.page( curr.path )
const baseFolder = app.vault.getAbstractFileByPath(dvCurr.file.folder)

const sel = tp.file.selection()
if ( !sel ) {
  windows.alert("Please select some text to be extracted")
  return;
}

const newFile = await tp.system.prompt("New file name")

const content = 
`---
tag: project
toBeInherited: ${ tp.frontmatter["toBeInherited"] }
---
Goal:: ${ dvCurr.goal }

${ sel }
`
/* 
console.log("Content", content)
console.log(curr)
console.log( dv.page(curr.path) )
*/

await tp.file.create_new(content, newFile, true, baseFolder)
tR = `[[${ newFile }]]`

_%>

To use it, change variables as you feel like it when entering into a template of its own. Then when you’re in a project file you’d want to extract stuff from, select the text to be extracted, and trigger the template. It’ll create a new file, fill it with content, leave a link to the new file instead of the selection, and open the new file for more editing.

The template utilises both Templater with the tp.frontmatter[ ... ], and dataview to pull values from the originating file (found in tp.template.target_file. It places the new file in the same folder as the file you’re extracting from. (If you change the true to false in the create statement, it’ll not go to the new file directly)

7 Likes

oh wow, thank you so much - I truly appreciate it and I’m kinda ashamed for not replying so long, please forgive me!

I finally got around to testing this and it works almost perfectly, with one little exception:
The link to the new file is not inserted instead of the selection, but it’s pasted right before the frontmatter of the new file. I’m sure this could be fixed by e.g. inserting an “open last file again” command in the second to last line, but I can’t seem to find out how…

Try switching the order of these two lines, so that the tR line is before the other line.

Thanks a lot Boss !

JibLord - If you’re comfortable showing us the code you eventually used, that would help us a ton to figure out how to customize for ourselves…thanks !!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.