Closed baseliners closed 2 years ago
So you want to be able to have a template for the filename and content of a note?
Lets say I create a new command Create Note from Template
. How should that command work?
I haven't used the Templater Plugin yet but I guess you will have a dedicated folder with template files in it. You could now enter this path in the preferences of the Create Note from Template
command. Activating it will show a searchable list with all the templates from the folder that you entered in the preferences. After selecting one it will open the normal Create Note
form where filename and content will be prefilled with the values from the template.
Now as I can tell from what you wrote, the Templater Plugin supports some placeholders (e.g. Zettelkasten/date) which will be replaced when creating a new note from a template. To have this functionality in Raycast I would need to implement these placeholders too.
Could you tell me which placeholders have to be added and what syntax is being used to mark placeholders? (e.g. {{date}}
)
Do you think this would come close to the templater experience? Anything to add/remove?
Thank you for the feature request!
Hi @baseliners,
any thoughts on this?
Hi @marcjulianschwarz - the way I was thinking about this is simpler (I think). i.e. your raycast plugin would invoke whatever mechanism Obisidian is using to create a new note using a Templater template. Not sure if the advanced URI plugin already handles templates, but if yes, it might be as simple as invoking a new note creation URI for a note in a certain folder, and if that folder has a template associated with it in Templater, that template gets used.
Personally, I'd be OK losing the form functionality that you currently have and have the plugin just drop me directly into Obsidian. If you wanted to parameterize, I'd parameterize the folder where a new note is being created, and allow for keyboard shortcuts to be assigned to each folder. i.e. I can assign a keyboard shortcut to create a note in Inbox, and another shortcut to create a note in folder XYZ, etc. This would provide a lot of flexibility and you wouldn't have to duplicate the templater functionality in your plugin. Thx!
Hi @baseliners,
thank you for the clarifications. Now I understand how the Templater plugin works, didn't know about the folder-template-association.
In the Create Note
preference section you can now enter a list of folders.
These folders will show up as actions in the command. Triggering them will add a new empty file in the corresponding folder. You can still override the path using the form or you could add a filename with the form. I think the notes content will be replaced with the template.
Open for feedback :)
Right now the shortcut for every action will be created automatically (counting from 0 to 9). I might need to change this behavior as some of these keyboard combinations are already in use by the OS.
This sounds great! How can I try it out?
You could download/clone this repository, then navigate to the folder and run npm install
and npm run dev
. The extension should then be visible in Raycast.
@baseliners let me know when you were able to test it.
Thanks. I was able to install and run it, but when I trigger the action for the Inbox folder, it tries to create a note with the filename Untitled.md instead of the filename that should be generated via the Templater template. Here's what my template looks like for the Inbox folder (i.e. the following line is what the template file associated w/ Inbox contains):
<% tp.file.rename(tp.date.now("YYYY-MM-DD") + " ") %>
So in Obsidian, if I create a new note (I have Inbox as the default location for new notes), the filename generated would be something like 2022-04-23<my_text>.md
(I add text manually after the date so it ends up making the filename unique).
I suppose the extension is bypassing the Templater somehow. Wonder if there's a way to have Templater still trigger even if the note creation is triggered by the Raycast extension?
Templater will trigger. I tried some of the examples from Templaters website and they worked.
I tested your template too and it worked fine for me. It renamed the Untitled.md
file.
Maybe the plugin isn't enabled or the template hasn't been selected in Templaters settings? Do you see any errors?
This shows it working:
As you can see Obsidian will throw an error that the file doesn't exist because it got renamed (Raycast is trying to open the old file name, this can be disabled in the extensions settings).
OK great, figured out the issue. I already had a file named Untitled.md in my Inbox so it was preserving that file. May be worth choosing another default name for the temp file?
Also, noticed that if I use the Command+Shift+return shortcut to create the note, it does create the file but does not drop me into the note. If I hit Command-K and then select the action for Inbox, it does drop me into the note that was just created. Not sure if this is intended behavior? I have the checkbox checked for "Open note on Creation" so was expecting the note to be opened via the keyboard shortcut as well.
Btw, is there a way to set a global shortcut for the action to create a new note in Inbox? I set a global shortcut to "Create Note" but would be nice to have a shortcut for creating a note in a specific folder as well.. but maybe this is something that Raycast needs to support?
Which default name would you suggest?
Can't reproduce this behavior. Both the shortcut and manually selecting the action from the list works for me.
I don't think there is a way to set global shortcuts for actions. The only way this would work is to create commands for each folder. However I don't think that this would comply with Raycasts guidelines for extensions. For "non-tech people" this could be quite confusing.
@baseliners any suggestions?
I can add a preference where you can choose the default note name.
Hi @baseliners,
I just pushed a new version. You can now specify a default note name for the Create Note
command which is being used when the name field is left empty.
Hi @baseliners, version 1.5 has been released and it includes your feature request. Thank you for the contribution.
Would be great to have a command to create a new note in Inbox that uses the template assigned to new notes in Inbox via the templater plugin (eg I have a template for any new note in Inbox that creates a prefix for the filename with today's date in almost-Zettel format). Thx for this plugin!