New note from templater suggester

What I’m trying to do:

I’d like to create a new note from a meeting minute template (I have a template for this) in the same folder as my master project note. The suggester items should return results from a dataview query that looks for property type (which is set to “projects”, “writing-projects” and “areas”). Unfortunately I can imagine it but I’m not so skilled to write the right code.
So let’s say I have three master projects notes (actually lot more, that’s why I’d like to have the list automatically created):

- Research project (which as yaml property type = project); the note is in folder "Projects"
- Writing project (which as yaml property type = writing-project); the note is in folder "Writing-projects"
- Other work tasks (which as yaml property type = area); the note is in folder "Areas"

I’d like to invoke the templater suggester to make me choose the project for which I need a meeting minute (which is always the same) and save the note in the same folder as the master note.

What I’ve tried:

For the dataview part I have this query:

```dataview
table
FROM "00 - Agenda"
WHERE type = "project" OR "another-type" OR "another-type2"
```

But I don’t know why it returns unexpected results: I think it should return notes in folder “00 - Agenda” whose ‘type’ field is one of the three but what I get is almost every note in that folder (???)

For the templater suggester I have no idea apart from that I could use app.plugins.getPlugin("dataview").api.tryQueryto make templater run the query…

Any help very appreciated…

You should be able to get a significant chunk of the code from here:

1 Like

Thank you @AlanG ,
I’m afraid your script goes far beyond my skills; for the moment I found a workaround that’s not as practical as my idea but it works: a QuickAdd that makes a new note from template and asks where to save it presenting the list of folders where my master note resides; I have to filter manually through much more notes but it works…
Anyway, for curiosity sake, I asked AI to write it. Even though I get a parsing error I paste it below in case someone more skilled is interested in debugging it.
The idea is:

  • filter out master notes that have a “project”, “writing-project” or “area” in their type property
  • get the name and path of these notes
  • create a new note from a “meeting minutes” template, naming it “YYYY-MM-DD - My Meeting Note Name” and save it in the same folder as the master note.

Here’s the code chat gpt gave me:

<%_* 
// Retrieve a list of projects with their paths
const projectQuery = `table file.path FROM "00 - Agenda" WHERE type = "project" OR "writing-project" OR "area"`;
const projectResults = await app.plugins.getPlugin("dataview").api.tryQuery(projectQuery);

// Extract project names and paths
const Projects = projectResults.values.map(project => ({ 
  name: project.name, 
  path: project.file.path // Assuming DataView provides path information
}));

// Use Templater suggester to get user input for project selection
const selectedProject = await tp.system.suggester(item => item.name, Projects, true, "Select a project...");

// Check if a project is selected
if (selectedProject) {
  // Prompt the user for the name of the new note
  const newNoteName = await tp.system.prompt("Enter the name for the new note:");

  // Check if a name is provided
  if (newNoteName) {
    // Create a new note from the "Meeting Minutes" template in the same folder as the project
    const templatePath = "path/to/meeting template.md"; // Update with your actual template path
    const newNotePath = `${selectedProject.path}/${newNoteName}.md`;

    const templateContent = tp.file.read(templatePath); // Read the content of the template
    tp.file.save(newNotePath, templateContent); // Save the content to the new file
  }
}
_%>

:slightly_smiling_face: