How to automate excalidraw dynamic file naming and moving files in a directory using templater

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

What I am trying to achieve is everytime I create a new excalidraw drawing, it appends the file location based on the tag into the correct folder/sub folder. For example, when I create a new drawing, I give it a tag of ‘personal’ it should automatically read that and append the file name to this format - {TAG_NAME}-{MMDD}.excalidraw and put it in the personal folder.

I also wanted to see if I could some how have like a dropdown menu in the excalidraw file template that I have where it would automatically put in the current date, a dropdown menu to choose tags from.

something along the lines of this. I am fairly new to excalidraw and templater although I have used obsidian for a while.

Things I have tried

I have this file which is called
date_and_tag_template.md

<!-- Excalidraw Template --> 
**Tag:** <% tp.prompt("Enter the tag") %> 
**Folder:** <% tp.prompt("Enter the folder name") %> 
**Date:** <% tp.date.now("YYYYMMDD") %> 
<!-- Content here will be used as the default content in new Excalidraw files -->

and then this templater file called Excalidraw_File_handler.md

<%*
const { moment } = tp; 
const excalidrawFilePath = tp.file.path();
const excalidrawFileName = tp.file.title; 
// Define the target folder 
const targetFolder = "Excalidraw-Drawings";  // Change this to your target folder 
// Function to read tags from the file 
const readTagsFromFile = async (filePath) => { 
const fileContent = await app.vault.read(app.vault.getAbstractFileByPath(filePath)); 
const tagRegex = /#(\w+)/g; let tags = []; 
let match; 
while ((match = tagRegex.exec(fileContent)) !== null) { tags.push(match[1]); } return tags; }; // Function to rename and move the file 
const renameAndMoveFile = async () => { const tags = await readTagsFromFile(excalidrawFilePath); if (tags.length === 0) { new Notice("No tags found in the file."); return; } // Use the first tag if multiple tags are present 
const tagName = tags[0]; const dateStr = moment().format('YYYYMMDD'); const newFileName = `${tagName}-${dateStr}.excalidraw`; const newFilePath = `${targetFolder}/${newFileName}`; // Move and rename the file 
await app.fileManager.renameFile(app.vault.getAbstractFileByPath(excalidrawFilePath), newFilePath); new Notice(`File renamed and moved to ${newFilePath}`); }; // Execute the rename and move 
renameAndMoveFile(); 
%>

But whenever I create a new drawing, I am not prompted to add a tag or folder and when I try to run the Excalidraw_File_Handler.md it throws me an error saying “No Active editor. cant append templates”

I do not know what I am doing wrong here.

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