Tp.file.cursor within a templater template

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

I’ve created a customized task bullet that automatically attaches relevant tags. However, when I input the task, I want to have the cursor placed where I’ll be defining the task (in below code, where ‘ZZZ’ is positioned). This has proven to be challenging. The templater code I’m using is

<%*
// Read the value of ‘Entity’ from the YAML frontmatter
const entity = tp.frontmatter[“Entity”];
const urgency = await tp.system.suggester(t => t, [“ASAP”, “Soon”, “No_Rush”]);

// Check if the entity value exists
if (entity) {
// Insert the tag with the entity value
tR += - [ ] ZZZ #${entity} #${urgency};
} else {
// Handle the case where the entity value is not found
tR += #UnknownEntity;
}
%>

Things I have tried

I’ve tried inserting <% tp.file.cursor () %> into the code (as per Obsidian Templater documentation) but it doesn’t work for me. Am I missing something simple? Thank you!

Instead of

<% tp.file.cursor () %>

try with

<% tp.file.cursor(1) %>

Thanks for advice, but I get a Template Parsing Error (invalid or unexpected token). Appreciate effort, of course…

the error is thrown (regardless) because you are not using standard “dumb” quotes (") but smart quotes: – a no-no in scripting…

also, you may need to use backticks for parts after tR

then…while i’m not sure what you want to do with the frontmatter property and the separate adding of a checkbox…
…the adding of the cursor within the script should be done with escaping the wrappers…if i remember correctly…?
something like

    tR += `- [ ]` + `\<\% tp.file.cursor(1) \%\> ` + `#${entity} #${urgency}\n`;

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