shabegom / buttons

Buttons in Obsidian
The Unlicense
455 stars 47 forks source link

Feature requests regrading template and input prompt #59

Closed ONLYA closed 5 months ago

ONLYA commented 3 years ago

This is a good plugin and I like it. I think that this needs more features to make it a more useful plugin. There are 2 suggestions.

  1. [x] The button can create notes from a template. However, it cannot load the template commands inside the template during the creation. If the button can create a note from templates with built-in template commands or the Templater ones, this will be a better tool of UI for productivity.
  2. [x] Input prompt is another powerful feature to be added. With it, I can create lines, notes, files with customised input to adapt the practical uses. For example, an input prompt will pop up when you click the button to request the filename of the created notes from templates.

Those are my suggestions. I can see great potential from this plugin to be used with Dataview and Templater. I hope that this plugin will make Obsidian note-taking a more user-friendly process with an easy UI like Notion.

shabegom commented 3 years ago

The template buttons should run Templater commands. So in theory you could insert a "template" that runs a prompt and then inserts the text into the current note:

<%* const prompt = tp.system.prompt("what's up?") %> <% prompt %>

type append template action prompt template note

You could also add the templater prompt into the button itself and use templater true to run it on click.

I'm not sure I understand your first idea..

ONLYA commented 3 years ago

Thanks for your reply. I found the command tp.system.prompt("what's up?") will run at first, turn the input into a static field and never ask a prompt for the next click again. I may need to workaround to find out a method to do it. (I am using it with Dataview. What I am trying to do is to make an "Add new" button so that I don't have to create a new file and apply a template into it manually.)

As for the first idea: let's say we have got a template file whose content is:

---
date: <% tp.date.now("HH:MM") %>
---
# Timeline

Its filename is assumed to be TEMPLATE New Timeline.md. Then inside another file, we have a button like:

name Add new
type note(TEST abcdefg, split) template
action TEMPLATE New Timeline
templater true

When I click it, it will generate a file with the content of:

---
date: <% tp.date.now("HH:MM") %>
---
# Timeline

As you can see, the template command is not called during the creation of the new file.

ONLYA commented 3 years ago

And the behaviour of the following block code:

name Add new
type note(<% tp.system.prompt("what's up?") %>, split) template
action TEMPLATE New Timeline
templater true

will generate an error message There was an error! Maybe the file already exists? while it eventually works properly.

Or I can use HTML with javascript inside templater to achieve that. Like this:

Name: <input type="text" id="fname" name="fname">
```button
name Add new
type note(<% document.getElementById("fname").value %>, split) template
action TEMPLATE New Timeline
templater true
```
ONLYA commented 3 years ago

I just need to enable a setting within the Templater's configurations to make it render the command. I still find it a bit buggy with user script but I believe it is on Templater's side.