What I’m trying to do
I’d like to user Templater and Buttons to auto-populate inline metadata Foo:: in a new file, based on criteria from the present file. For example, if I’m in File A.md, I want a templater script or a button that can:
- Create a new
File B.md based on template Template 1.md
- Find
Foo:: in the new File B.md and change it to Foo:: File A
Note: I know that Buttons can replace a specific line in an file, and I could have it replace the specific line # that contains Foo::, but I’d prefer to run javascript to search and replace for Foo:: in case I change the template and it’s on a different line#.
What I’ve tried:
As an initial step I wanted to see if I could pass a variable from a button to a templater codeblock in a template. If that worked, I could use that variable along with javascript in a templater codeblock to search and replace Foo::. But passing a variable like below did not work:
In File A.md, this button:
name Make an Hourly Note
type note(<%* let foo = tp.file.title%>) template
action Template
templater true
In Template.md:
<%*
tp.file.create_note(foo);
%>