Templater tp.system.prompt to select/link existing file

What I’m trying to do

I am trying to use a templater template for new note creation that prompts me to enter another note’s name. I would like to keep the automation inside a template so that I can reference the template in the kanban:settings section of a kanban note.

%% kanban:settings

{"kanban-plugin":"basic","new-note-template":"_/templates/projects/topic cards.md","new-note-folder":"Projects"}

%%

Things I have tried

I can do this manually with

[[<% tp.system.prompt(“Enter Primary Project Name”) %>]]

But I have to know the correct file name or alias. I would like to see a selection list, like when I am linking something.

Any ideas?

This is the full template file

up:: [[<% tp.system.prompt(“Enter Primary Project Name”) %>]]
tags::

Meetings

Notes

Related

TABLE file.mtime.year + "-" + file.mtime.month + "-" + file.mtime.day as Modified

FROM [[<% tp.file.title %>]]
and !outgoing([[<% tp.file.title %>]])

SORT file.mtime desc

Created on: [[<% tp.date.now(“YYYY-MM-DD”) %>]]
<% await tp.file.move(“Projects/Project Tasks/” + tp.file.title) %>

Instead of using Templater’s prompt dialog, you’ll want to use the suggester one instead.

Suggester even has a built in way of displaying files within your vault. Here’s an example from the Templater Discussion board about filtering the file selection to only include files from a single directory.

As a warning, you will have to use TemplaterJS instead of just the regular Templater syntax which will run JavaScript on your vault.
Be careful when running anything found online

That’s it! Thank you!

New Template

<%*
const tag = “#project”;

const filteredFiles = app.vault.getMarkdownFiles().filter(file => {
const tags = tp.obsidian.getAllTags(app.metadataCache.getFileCache(file));
return tags.includes(tag);
});
const selectedFile = (await tp.system.suggester((file) => file.basename, filteredFiles)).basename;
-%>

up:: [[<% selectedFile %>]]
tags::

Meetings

Notes

Related

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