Templater Prompts Not Evaluating Properly in YAML Frontmatter and Body

'm currently trying to create a customer call note template using Templater, and I’m running into some issues. I’ve designed the template so that I can prompt for inputs like customer name, call date, contact information, etc., using Templater’s tp.system.prompt() commands. I need these values to be filled in the frontmatter and throughout the note body for consistency.

Here’s what the current template looks like:


type: customer_call
customer: ‘[[ <% tp.system.prompt(“Enter Customer Name”) %> ]]’
contact_info: <% tp.system.prompt(“Enter Contact Email or Phone”) %>
call_date: <% tp.system.prompt(“Enter Call Date (YYYY-MM-DD)”) %>
call_time: <% tp.date.now(“HH:mm”) %>
medium: <% tp.system.prompt(“Enter Call Medium (e.g., Phone, Zoom)”) %>
created: <% tp.file.creation_date() %>
last_modified: <% tp.file.last_modified_date() %>
Folder Location: <% tp.file.folder() %>
tags:

  • call
  • customer_interaction

<% tp.date.now(“YYYY-MM-DD”) %> - Call with [[<% tp.frontmatter.customer %>]]

Customer Information

  • Name: [[<% tp.frontmatter.customer %>]]
  • Contact: <% tp.frontmatter.contact_info %>

Call Details

  • Date & Time: <% tp.date.now(“YYYY-MM-DD”) %> <% tp.date.now(“HH:mm”) %>
  • Medium: <% tp.frontmatter.medium %>

Issues Discussed

  1. Issue 1:

  2. Issue 2:

  3. Issue 3:

Resolution

  1. Action 1:

  2. Action 2:

  3. Action 3:

Customer Feedback

  • Areas for Improvement:

  • Positive Points:

Reflection

  • What went well:

  • What could be improved:

  • Lessons Learned:

Linked Notes

The problem I’m facing is that while the frontmatter fields (customer , contact_info , call_date , etc.) are getting populated correctly, the prompts within the body of the note (<% tp.system.prompt(...) %> ) are not being evaluated as expected. Instead, these placeholders stay in the note without being replaced by the actual input values.

For example, after running the template, the frontmatter turns into:


type: customer_call
customer: ‘[[ John Doe ]]’
contact_info: [email protected]
call_date: 11/11/1111
call_time: 14:04
medium: Zoom
created: 2024-10-17 14:04
last_modified: 2024-10-17 14:04
Folder Location:
tags:

  • call
  • customer_interaction

However, the body still contains:

2024-10-17 - Call with [[[[ <% tp.system.prompt(“Enter Customer Name”) %> ]]]]

Customer Information

  • Name: [[[[ <% tp.system.prompt(“Enter Customer Name”) %> ]]]]
  • Contact: <% tp.system.prompt(“Enter Contact Email or Phone”) %>

Call Details

  • Date & Time: 2024-10-17 14:04
  • Medium: <% tp.system.prompt(“Enter Call Medium (e.g., Phone, Zoom)”) %>

The prompts in the body are not being replaced as they should, and I can’t figure out why.

The tp.frontmatter.something is to be used when inserting a template into an existing file. You can’t use it to refer to frontmatter you’re in the process of creating when executing the template in a newly created file.

All is not lost though, as you can store the result of the previous prompt and use that later on like in the following example:

<%* 
const contact_info = await tp.system.prompt("Enter Contact Email or Phone")
const call_date = await tp.system.prompt("Enter Call Date (YYYY-MM-DD)")

_%><% "---" %>
contact_info: <% contact_info %>
call_date: <% call_date %>
<% "---" %>

Some more text

## Customer information

- Contact: <% contact_info %>

This template utilises a code block at the start to do all your prompting, before it actually inserts any text into the file. (One could assign output in that first code block by assigning stuff to tR, but I tried keeping it easy)

Using that somewhat strange <% "---" %> is a way to handle frontmatter fences without causing the template file itself to misbehave.

1 Like

Try use hook to postprocess note:

      tp.hooks.on_all_templates_executed(async () => { 
        const file = tp.file.find_tfile(tp.file.path(true)); 
        await app.fileManager.processFrontMatter(file, (frontmatter) => { 
          frontmatter["alias"] = alias;
        }); 
      });

Hey @holroy,

Just wanted to drop by and say that your solution worked perfectly for me! Not only did it solve my immediate problem, but looking over your code example really helped me understand better how Obsidian’s Templater works. I finally see how storing the prompts first and then using them later keeps everything much cleaner and more reliable.

I can’t thank you enough for the detailed explanation and that nifty trick with <% "---" %> to handle the frontmatter! Honestly, it all just clicked after seeing it written out like that.

Also, I have a quick question: How do you add those clean code blocks to the forum posts? I’d love to be able to format my future posts as neatly as yours. Any tips on that would be greatly appreciated!

Thanks again for taking the time to help. You’ve made my Obsidian workflow so much smoother!

Add more backticks… :smiley: Typically when I present a query I enclose the query in four backticks, so that the three backticks of the query are preserved. (In order to present the example below I needed to use five backticks… :slight_smile: )

````
```dataview
LIST LIMIT 5
```
````

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