How to trigger Templater when adding file link to the property called "parent"

Hello! I am quite new to the templater plugin, and I would like to use it functionality to execute this following steps:

  1. I add some properties (including “parent”) onto new file.
  2. I link file on to the “parent” property
  3. The new file will moved to the same directory as the “parent” file directory.

Basically what I said is, I want to trigger templater plugin to move my newly created file to the same directory as the linked file in the “parent” property. (it is like moving the children files to the same folder as the parent’s one)

something that I tried just now is using move_file.js in my script file like this

module.exports = async (params) => {
    const { app, file } = params;

    // Get the parent file path from the frontmatter
    const parentFilePath = file.frontmatter.parent;

    if (!parentFilePath) {
        console.log("No parent property found in the frontmatter.");
        return;
    }

    // Get the parent file object
    const parentFile = app.vault.getAbstractFileByPath(parentFilePath);

    if (!parentFile) {
        console.log(`Parent file not found: ${parentFilePath}`);
        return;
    }

    // Get the directory of the parent file
    const parentDirectory = parentFile.parent.path;

    // Move the existing file to the parent directory
    await app.fileManager.renameFile(file, `${parentDirectory}/${file.name}`);

    console.log(`Moved file to: ${parentDirectory}`);
};

and template file with this:

---
parent: "{{parent}}"
---

<%*
const moveFileScript = await tp.user.move_file({ app: tp.app, file: tp.file });
%>

but it returns parsing error

Ok so basically I have idea that I did yesterday and it works as I intended. I used specific tags for each of the file with the same parent directory (the solution is i use tag #0- to move the file that has parent MOC with code 000 - ... on the folder named 000. I used simple plugin that is Auto Note Mover.

I couldn’t get to work on the templater, even tried with QuickAdd plugin but yet again couldn’t figure it out how to work (but now I know how to work this plugin).

So basically, I use hashtag to trigger moving file to parent file’s directory instead of when I add parent property with file link. Not the exact solution but it works the way it I want, in a way.

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