Templater / Buttons: Create new note and set specific property values?

What I’m trying to do

Using the following plugins:

  • buttons
  • templater

I would like to create a button that:

  • creates a new file from a template
  • sets specific property values on the new file

Requirements:

  • The solution must use a template that has several property keys with undefined values
  • There will be several buttons using the same template, with each button setting different property values for the created file.
  • The values to be set on the new file will (partly) be taken from the ‘active’ file’s properties , i.e. the file on which the button is pressed.

Additional information:
The buttons will be part of a template i will use as the dashboard for new projects. The dashboard should provide buttons to create different types of notes for the same project. The property values then will be used by Obsidian Bases to categorize project related notes.

I would use metabind over buttons for this.
You could have buttons trigger templater code that can take arguments from the button to run frontmatter updating after creating a new template.

@cheezopath this is what I have ATM. It works more or less.

It will give me the main page for a new project, from which I can create new project files in the same folder with appropriate properties such that Bases will display them on the dashboard (last line).

Main problem is - inserting this as a template for a new project will execute the templater code inside of the button, which is quite undesirable.

What do you think? (I’ll give metabind a try ASAP.)

P.S. Just noticed - the nested code block messes with the rendering. Sorry for that.

Test Project Dashboard

---
proj_kind:
  - main
proj_name: testname
proj_client: testclient
---

```button
name New Note
type append text
templater true
action <%*
	// template used for new file
	const name_template = "template_project_file"
	const file_template = tp.file.find_tfile(name_template)
	// original file (from which the new file is being created)
	const file_original = tp.file.find_tfile(tp.config.active_file.path)
	// create new file
	const file_newfile = await tp.file.create_new(file_template, await tp.system.prompt("Name:"), true)
	// set properties on new file based on original file's properties
	await app.fileManager.processFrontMatter(file_newfile, (frontmatter) => { 
		frontmatter["proj_kind"] = "main";
		frontmatter["proj_name"] = tp.frontmatter["proj_name"];
		frontmatter["proj_client"] = tp.frontmatter["proj_client"];
	});
	%>

Project Files

![[_projects.base#project files]]

with metabind you can have a button with something like this:

label: This is a button
icon: ""
style: default
class: ""
cssStyle: ""
backgroundImage: ""
tooltip: ""
id: ""
hidden: false
actions:
  - type: runTemplaterFile
    templateFile: mytemplate.md

(metabind comes with a button builder command so you don’t need to remember all that)

this way you can shift that templater code into a different file and rather than getting executed when the new file is made, it only triggers if you click the button