Run Templater script twice?

What I’m trying to do

I have a template trigger whenever I type a keyword inside a fresh link. In this case, “[[moc-tag]]” transforms into “[[tag]]” after I clicked, updating the link, thus the name of it to “tag” instead of “moc-tag”.

My problem is, when I want to create a “moc-tag” link in a new file AFTER the creation if the first “tag” file - so when a “tag” file already exists in destination folder - the process doesn’t work. Instead, I get a “Destination file already exists!” error in the console.

What I’m trying to do is, whenever, after the first click, I recreate a “moc-tag” link, instead of trying to create a “tag” file and transforming “moc-tag” into “tag”, it doesn’t try to create a “tag” file, but check if there’s already an existing one, and if this is the case, appends to the existing “tag” file, instead of trying to create one, leading to the “Destination file already exists!” error…

I have followed the logic of @BryanJenks and @PamelaWang to implement the triggers.

Here’s my (or their) original code:

var cleanTitle = tp.user.getTitleSnippet(tp.file.title) 
var title = `${cleanTitle}`;
title = `${title}`;
await tp.file.rename(`${title}`);

setTimeout(() => {  
  const newFilePath = "0020_MOC's/" + title + ".md";
  app.vault.rename(tp.config.target_file, newFilePath);
}, 200);

# <%* tR += title %>

<% tp.file.cursor() %>