Zettlr: [FEATURE] Support for templates to be used when creating a new note

Created on 5 Jul 2020  ·  18Comments  ·  Source: Zettlr/Zettlr

Description

I press ctrl-n to create a new note, and after accepting the title of the file (or altering it) the new note shows up in the editor
with pre-generated content, so that I only need to fill out the title, content and links

At the moment I am copying the YAML Frontmatter section into every new note, which is tiring.
Besides the YAML Frontmatter section, it would also be nice if I could make a template for the rest of the note with a "Link" and "Content" Section with headers (example follows)

Such functionality would make it faster and easier to take/write notes, which I assume is a noble goal to strive for in a notetaking app :wink:
I know some people use AutoHotkey for this, but that increases complexity and doesn't make it easier to take notes.


There was a similar issue #502 (YAML Frontmatter templates) that was closed referencing that issue #90 would "fix the issue" or be a workaround. However issue #90 is now closed, so therefore I open this issue and suggest the following solution...

Suggested solution

The functionality is _almost_ there!

In the AutoCorrect feature of Zettlr you can choose that __:template:__ will be replaced with:

title: "Title" 
author: 
    - Author 
keywords:   
    - keyword 
... 
# Titel     


_____________________________________________  

## Links   


 ______________________________________________

Problem is that the structure of this replacement text isn't preserved, meaning that spaces, tabs and linebreaks will not be there when you type :template: in your note. Instead the replacement text looks like this:

--- title: "Titel" author: - Author keywords: - keyword ... # Titel _____________________________________________ ## Links ______________________________________________

so..

  1. Step one would be to alter this behaviour, so that AutoCorrect can save/format the replacement text correctly.
    This basically makes AutoCorrect a template/snippet feature in itself, and allow users to have many different templates for different usecases (if that could be useful).

  2. Step two would be to add a section in the AutoCorrect pane in Preferences. Here users can turn on "Default template for new notes" - same way that they can turn on autocorrect - and let the user use a dropdown menu to choose their preferred AutoCorrect/Template/Snippet to use as the new note.

  3. Implement the functionality so that a new note is populated with the chosen template

Since the above functionality could pollute the AutoCorrect feature, you could create a new pane in preferences called "Templates" or "Snippets" and only have the functionality from 2. and an empty list in there.
I see several benefits of this:

  • When the functionality is implemented, users have a clearer distinction of what the functionality is for, so that correct formatting of spacing and valuta isn't mixed with templates of different sorts.
  • The list of both sections will be shorter and have less content to scroll through.
  • While implementing you could copy the entire functionality from AutoCorrect, so that any bugs or the likes, ~doesn't~ _in lesser ways_ affect the existing stable functionality.

When this raving feature is implemented and the crowds are going wild, one could consider expanding it with the possibility of adding variables such as time and date to templates.

I hope you can see the usefulness of such a feature, and that I am correct in assuming that most of the footwork has been made for such a feature qua the AutoCorrect feature.

Thank you

feature pinned mid v1.8.x

Most helpful comment

Hmm … I'm still thinking the best way would be to have one shortcut to invoke a template selector from a dropdown, with the order predescribed by sorting the available templates in the dialog

All 18 comments

Thanks so much for opening up your first issue here on the repository! 🎉 We would like to warmly welcome you to the community behind the app! ☺️ We'll check in soon and have a look at your issue. In the meantime, you can check your issue and make sure it aligns with our contribution guidelines! Here's the comprehensive list:

Enhancements

An enhancement takes a feature and improves or alters its behaviour. Please make sure to argue how your proposition will aid non-technical text workers, and why it can't be emulated easily with other features or apps!

Feature requests

Feature requests introduce whole new features into the app. This requires a lot of work, so these might be turned down if the implementation costs supersede the benefits we expect to see from implementing it. Please do not be disappointed if that happens. It likely has nothing to do with your great request but simply with us and our missing resources!
You can of course always ask someone to implement this feature, because a PR with a working new feature has much higher chances of being merged! :)

Bug reports

Please note that one of the main reasons for why bug reports cannot be addressed is that there's not enough information for us to find and fix the bug you describe, so make sure you try to pinpoint the bug as close as possible.
The ideal bug report for us has two qualities:

  1. The bug is always reproducible, at least within a certain context. 2. We know exactly what specifically goes wrong, and there is consensus on
    what should happen instead.

Please note that if you encounter behaviour that does not align with your expectations of what would happen, this might as well be simply intended behaviour and we need to simply _clarify_ why the behaviour is the way it is. This is not to be considered a bug and such issues may be closed! Suggest an enhancement instead!
But now, have a great day and thank you again!

Related #90

some further elaboration/ideas...

  • Please make the textbox for editing templates multi-line (I guess this would necessitate a separate pane for templates)
  • You could create a tutorial template, that would be enabled after install, so that the first time the user creates a new note the template will be invoked showcasing the functionality
  • Maybe add a standard set of templates to ship with Zettlr that would go well with the Zettelkasten Method. This would make the list look a bit more populated/inviting as well, and inspire to ones own creations

Finally... (I'm just floating this idea for further down the line)

Give the user an "Make template from selection" option in the right click menu in the editor, when text is highlighted/selected.
The "name" of the template created, could be something generic the user would then alter afterwards, or maybe a small textbox shows up where the user could input their "name"/template syntax.

I like the idea of creating notes from templates and I think it should not piggy back on AutoCorrect. Obviously, AutoCorrect source code can be reused to implement it, but that is an implementation detail. In my opinion, the UI should make clear distinctions between the two (a separate pane in the Preferences sounds good).

This feature has also been discussed in Reddit. I really liked one of the ideas there and wanted to add it under this discussion:

Make it possible to create multiple templates. There could be a default template (that would be tied to Ctrl+N, but another keyboard shortcut (Alt+N ?) would trigger a dropdown dialog where the user can select an alternative template for the new note.

Hmm … I'm still thinking the best way would be to have one shortcut to invoke a template selector from a dropdown, with the order predescribed by sorting the available templates in the dialog

I agree with canpolat in thinking it would be best to have separate section in the settings for these templates/snippets

@nathanlesage When you're saying the best way would be via a shortcut and a template selector

  • is that opposed to using the AutoCorrect input functionality - e.g. using: :for entering templates?

The most important thing for me is the possibility to make new notes use a default template, so I have do not have to choose from a selector for that.

The most important thing for me is the possibility to make new notes use a default template, so I have do not have to choose from a selector for that.

Mh … I can only see an option for this. I for one like my files to be empty on creation, but a small toggle "Apply first template by default" should be no hassle.

But the idea would be something like the :-thingy. I have to think this through!

a small toggle "Apply first template by default"

Exactly - the option should of course still be there to start with an empty note.
You could also choose a drop down next to the toggle, instead of relying on the order of templates.
I think that would be easier for the user (and for you if at some point it makes sense to be able to order the templates for other reasons), but I don't know what would be easiest to implement.

But the idea would be something like the :-thingy.

the :-thingy is good and should pose no problems to reuse if users are not allowed to use the same keywords in autocorrect and templates?

...Additional idea for the templates:

Make it possible to be able to specify (or not specify) \n/linebreak characters at end or beginning of multiline, so that users get the formatting they wish if they insert the template midline.
For more accessibility - checkbox or drop down with number of lines for beginning and end of template, but then again... It is a markdown editor, so people should be able to fiure out how to put in a line break.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hello Stale Bot, I still think this would make a good addition to Zettlr.

I would love to take a stab at this implementation if no one else is already working on it. I agree with the sentiments expressed above that this feature should not be entangled with AutoCorrect. And, IMO we should think of this feature and snippets feature as separate too, because a template for note is something that will be triggered once in the lifetime of a note - at the time of note creation whereas a snippet can be reused many times across many types of notes. From an implementation point of view they may share code, but from a user perspective they are separate and trying to achieve one with another will result in sub-par user experience.

There will be two parts of implementation:

  1. A tiny button adjacent the "new" button, with a drop down arrow icon. Clicking on this button will show a drop down list containing top three used templates and an option to create a new note from template. Clicking this last option ("New note from template") will show a pop up with a list containing all available templates that are installed. Selecting the template creates a new note based on that template. No change to existing "new button" click behavior (unless the user change the default template using the settings page described next).
  2. An addition to the settings page - probably a new tab named templates that allows user to see the list of available templates, create new ones, edit, delete etc and also mark a template as the default template.

I can start working on this as two separate PRs if this approach sounds good.

I think it would be essential that you can choose a default template that works when you use the keyboard shortcut for new file so you won't have to mouse around to pick a template

Would really like a "note template" to be implemented as well! Most of my notes require the same structure, so typing this same structure every time I create a new note is really painfull...

I would love the ability to have several templates.

+1 This is necessary for optimal Zettelkästen organization.

+1 would really love to have this attribute!

+1 from me, too. I'm desperate for this.

Just to add a few comments:

  • It _really_ needs to be separate from autocorrect, so you can turn off autocorrect without losing all your templates!
  • I would love the ability to set different default templates for different folders. A template I might use for a software project idea makes no sense if I am writing a note about a character in a novel, for example.
  • With that in mind, could a template be just a simple markdown file in a Zettlr folder, but with a different extension (e.g. ztpl) and have Zettlr scan and pick them up to build the list automatically? I would much prefer working with templates to be as simple as working with regular Zettlr notes rather than a deep dive into a fiddly admin interface.

Yay ! Can't wait for this great feature ;)

Was this page helpful?
0 / 5 - 0 ratings