Skip to content

How to open existing file or use template if not exist? #1126

Answered by Zachatoo
wealthychef1 asked this question in Help
Discussion options

You must be logged in to vote

I've got a few examples here, though not sure if they'd work with the advanced URI plugin. It's the advanced URI plugin creating the file, not Templater. So you could check to see if the file exists, if it does, then delete the file that the advanced URI plugin created and just open the existing file instead.

I haven't tested this myself, but here's the basic idea.

<%*
const fileName = tp.date.now("YYYY-MM-DD") + " Piano Study";
const existing = tp.file.find_tfile(fileName);
if (existing) {
  // delete file created by advanced URI plugin if desired file name does exist
  await app.vault.delete(tp.file.find_tfile(tp.file.title));
  // open existing file
  await app.workspace.getLeaf().open…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wealthychef1
Comment options

Answer selected by wealthychef1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants