I am trying to make a template that is automatically created when a new file is made in a specific folder. I want it to do these steps:
- Prompt the user for a text input
- Set the filename to that input
- Create a property of “tags” with a tag of “ma222”
- Add the input within the file as text
Here is the code that I currently have for the template file:
<%*
// Prompt for the title
const title = await tp.user.prompt('Enter title name');
// Rename the file to the entered title
await tp.file.rename(title);
%>
---
tags: [ma222]
---
<%- title %>
---
Place holder text that will proceed here.
So for example, if I were to input “Test” as the filename, I want it to look like this:
When I created this template, the formatting of the properties section looked abnormal when I turned off source mode, with Obsidian changing the look of the “tags” text to a header 2, and creating a line above the “tags” text (The line above the placeholder text is intended):
When the correct view of the properties section should look like this:
When I attempt to create a file in the designated folder that I set in Templater’s settings, I do not get prompted for the title, and instead, I get a parse error:
plugin:templater-obsidian:6 Templater Error: Template parsing error, aborting.
tp.user.prompt is not a function
K @ plugin:templater-obsidian:6
What I have tried
I tried using tp.prompt instead of tp.user.prompt. It gives the same error. I also tried putting the YAML code of the properties before the javascript code, like this:
---
tags:
- ma222
---
<%*
// Prompt for the title
const title = await tp.user.prompt('Enter title name');
// Rename the file to the entered title
await tp.file.rename(title);
%>
<%- title %>
---
Place holder text that will proceed here.
When I format the text like this, the properties do display correctly in the template (not when creating files). However, I get the exact same error when I create a new file with this template.
I would appreciate any help with this, as I am very new to using Templater. Thanks!