Plugin: Create Notes from Templates

I couldn’t find an easy way to do this, so I made a quick plugin that lets me create Nodes based on templates. I don’t think this is quite the same as the Templater plugin - I want to choose a template to make a note from, insert info by hand, and have the Note created in the right place, with the info in.

Each Template (which is just a Markdown file in a certain directory) gets its own command in the palette, and can set what folder the note should be created in. There’s a popup to put in values for variables, so you can fill in info without leaving the current note.

It’s not at all refined or tested, but you can find it here: GitHub - mo-seph/obsidian-note-from-template: Simple plugin to create Notes from a template, and f

Caveats: you need to reload Obsidian to update the set of Template commands - but hopefully that doesn’t need to happen very often!

10 Likes

Thank you for this! But unfortunately, I can’t get it to work. I have placed manifest.jaon, styles.css and main.ts in the plugins folder. Also tried renaming the extension on main.ts to .js. Any idea what I am doing wrong?

You’re probably doing nothing wrong! It’s the first Obsidian plugin I’ve put out, so I’ll double check for ways to package it - otherwise you probably need build it locally, which could be a pain if you’re not set up for that.

Ouch :sweat_smile:

I think it should work now if you get the latest version - fingers crossed! This includes the main.js file.

I’ve now made a proper release here:

I’ve also expanded the plugin functionality a bit - you can configure what the selected text gets replaced with, and also autofill the text boxes with parts of the selection:

TemplateDemo

There’s quite an overlap with @Christian’s Quick Add plugin - I probably wouldn’t have made this if I’d found that first! I think there’s a different focus here, though - it’s very minimal and all the config is in the markdown templates.

2 Likes

New release!

0.1.5

Lots of new configuration - whether to replace text or not, whether to create notes and open in new panes, template changes load without reloading obsidian, new fields

3 Likes

New release - lots of updates:

  • Templates now loaded dynamically - no more restarts! (also: changed template folder selection to dropdown,command for re-indexing)
  • Added a choice type, e.g. {{suit:choice:hearts:spades:diamonds:clubs}}
  • Note filenames are now generated from a template string, either in config, or in template-filename in the template. Defaults to {{title}}, but all template fields available.
  • Added multiple replacement text possibility - If an array is given for template-replacement, then these will all be options in the template dialog
  • Many UI tweaks, fixed YAML parsing
2 Likes

Hello @mo-seph , the updates look great, thanks! A lot of amazing improvements. But have you had any problem loading dynamically the commands? I use a lot of plugins here (23) and maybe other plugin is messing with it (or maybe it’s an Obsidian configuration) but unfortunately FromTemplate is not being able to create commands and show them on command palette (Ctrl-P). And it’s not throwing any error message on console (Ctrl-Shift-I)…

I even tried the “Re-index templates” command but without success.

Quick check - are you in edit mode? I only see the template commands when I’m editing markdown.

Edit mode:

Preview mode:

1 Like

Thank you, @mo-seph . Didn’t know that. Is there a reason for that? One great usage (and it worked here for a day or less) was using a Button to fire a form and create a new note. It was so beautiful… :disappointed_relieved:

1 Like

Dear @mo-seph , another point: does the behavior changed in relation to frontmatter (YAML)? I guess (I’m not sure) the previous version was able to replace fields in frontmatter but the 0.1.6 doesn’t seem able to do it. Thanks!

It should work. There is a behaviour change, though - the frontmatter now needs to be proper YAML, which means values can’t start with { otherwise they are read as empty dictionaries (YAML would support address: {street: Baker, number 221b} for example). So you have to change

key: {{value}}

to use quotes:

key: "{{value}}"

I’ve updated the docs to mention this, as it surprised me!

If that doesn’t work, though, there’s a problem

1 Like

Can you share how you make that work? I didn’t know it was possible, and it sounds great!

1 Like

Thanks, @mo-seph, for the info about YAML. Didn’t know that. I confirm it’s working great now.

About the button, all I did was creating a button with “Buttons: Button Maker” dialog. It worked beautifully but only for some hours, I don’t know why:

```button
name New Partner (Form)
type command
action From Template: New Partner - FORM

^button-buttonNewPartnerForm

Hello @mo-seph (et al), I tried to create a macro (using macro plugin) to toggle to edit mode, call the form and toggle back to preview mode (read mode). Unfortunately I couldn’t find a command that worked (to toggle between edit and preview (read) mode). Bye!

I like the plugin. A small feature I noticed that when I invoke a template with “tags” or “aliases” (pre-populated or not) in the YAML they are removed from the note created. I can get around this by making these YAML required for population.

I don’t know if this is fixed with the new editor? It certainly lets me be in the preview/edit mode where everything looks nice, but still use the plugin.

Ah - that could be down to my YAML handling (at some point, I brought in a YAML library rather than going through it by hand, but it seems to have made life much more complicated for cases like this) - I’ll have a look.

Can you share an example template? I started an issue here: https://github.com/mo-seph/obsidian-note-from-template/issues/21

1 Like