shabegom / buttons

Buttons in Obsidian
The Unlicense
455 stars 47 forks source link

For Template New Note Buttons, allow manual naming of the new note in a pop-up window, which will allow Templater tp.file.title functions to run. #69

Closed DryIce1 closed 5 months ago

DryIce1 commented 2 years ago

Problem

Expected solution

for example, my current use case, where I would want to manually rename New Note:

image


I hope this makes sense and is useful for others.

DryIce1 commented 2 years ago

Perhaps I explained this problem more simply over here

MartynKeigher commented 2 years ago

You can do that already @DryIce1. Create a template based on the following code block and then tie the inserting of the template to a button! :)

<%*
const prompt = await tp.system.prompt("Title:")
const title = await prompt
await tp.file.rename(title)
tR += "# " + title
%>

---
#tasks #inbox
Completed:: 
Project:: [[<%tp.file.cursor(1)%>]]
Status:: #active
Priority:: 
Date Created:: <% tp.file.creation_date("dddd,  MMMM D, YYYY @ HH:MM") %>
Due Date::
Defer Date::
Recur Length::
DryIce1 commented 2 years ago

Hi @MartynKeigher, thanks for the snippet - it does what it is supposed to do perfectly! And I have added the tp.file.include function so that my Action Items Template can remain unaltered.

For any non-tech people who want to do something similar, here is my current set up.

Button

button
name New Action Item
type note(Title, split) template
action Templater - rename file title and include Action Item Template
templater true
color blue

Template 1 - rename file title and include Action Item Template

<%*const prompt = await tp.system.prompt("Title:")
const title = await prompt
await tp.file.rename(title)%>
<%-tp.file.include("[[Action Items Template]]")%>

Template 2 - tp.file.include - Action Items Template

#inbox

---
- *Back Matter*
    - **Date Added**:: 2021-10-28 15:20
    - **Do Date**:: 
    - **Due Date**:: 
    - **Done**:: 
    - **Recur Length**:: 
    - **Priority**:: #✅/P
    - **Status**:: #✅/S/1_Active
    - **Date Added**:: <%-tp.file.include("[[Timestamp]]")%>
    - **Person**:: 
    - **URL**::