Specifying note title and tags in templates

Recently the first version of the templates plugin was released. As always, for those who don't know what is templates plugin please check out Template Plugin.

There were a lot of requests for allowing users to specify title, tags in the template itself. So, here's what I've thought on this.

Currently we have two types of variables

  • Built In Variables - These are the variables that you can use directly in the template body. E.g. {{ time }}, {{ bows }}.
  • Custom Variables - These are the variables that you can define yourself and provide their values at the time of using the template.

The idea is to create third type of variables called Special / Reserved Variables. These are the variables that you can't use as custom variables and have a purpose other than being used in the template body. Currently I'm proposing two special variables

  • note_title - This can be used to specify the title of the created note/to-do using this template.
  • note_tags - This can be used to specify the tags (comma separated) to be applied to the note/to-do created using this template. If a tag with that name doesn't exist, it will be created.

Features of these special variables

  1. Both built-in and custom variables could be used for defining the value of these variables usin <% %> brackets.
  2. Their values can be used as normal variables in the template body.

Example of a template is given below.

---
name: text
project: enum(Project 1, Project 2)
note_title: Sprint <% bows %>
note_tags: sprint, <% project %>

---

Hi {{ name }},

This note was created on {{ datetime }}. The title of the note is {{ note_title }}. The tags applied to the note will be {{ note_tags }}. 

Cheers!

Please let me know, what do you all think of this feature?

UPDATE
We don't need to use <% %> in special variables and can use the same {{ }} brackets i.e. the following template will work.

---
name: text
project: enum(Project 1, Project 2)
note_title: "Sprint {{ bows }}"
note_tags: "sprint, {{ project }}"

---

Hi {{ name }},

This note was created on {{ datetime }}. The title of the note is {{ note_title }}. The tags applied to the note will be {{ note_tags }}. 

Cheers!
7 Likes

How will you handle it if a tag does not exist. will it be created or just not applied?

2 Likes

@JackGruber

1 Like

Totally overread. I think I sit today already too long at the PC.

2 Likes

I'd really like to be able to set the note title via templates. In fact the first thing I tried after installing the plugin was putting a custom_datetime tag into the template title, but it doesn't work. Confusingly, nothing happens if you have a template note with no body text, no error or warning just nothing.

I keep a journal in Joplin and give the notes datetime titles. I feed it into a static site generator so I need a specific format and none of the default options in Joplin work, so I was hoping to use the template to auto-title my notes based on the current custom formatted datetime.

So I guess that's a long winded +1 to this.

2 Likes

Isn't it what the note_title property is for?

1 Like

I have tried the example above for template variables but I get the errors:

note_title has an invalid type.
note_tags has an invalid type.

also the name field is wider that its dialog box.

template_result

I have tried using single and double quotes on the values but I still get the invalid type error.

EDIT:

Like @JackGruber I seem to have missed something vital when reading the post, namely, they are proposals. :man_facepalming:

1 Like

These seems like a good proposal to me. This also allows for later reserved variables for things like a due date or other metadata type things. Makes me wonder if there should be a better rule for name spacing, i.e. template_ so template_title, template_tags and let users know that at any time a template_ variable may become reserved so they shouldn't use them (even if you don't actively prevent it).

Other thoughts:

  • Would it be possible to keep the handlebars style tagging for those? I feel like switching tag styles is confusing. I realize that may be a huge technical hurdle though, so probably ok for a v1
  • FYI, I immediately feel like people will want / try to use these special variables in their note, so if that can be accommodated, it will probably be good. (for example, someone wants the note title at the top of the page, or to visually see the list of links)
1 Like

Indeed I missed that it was a recent proposal. Wouldn't it be possible to use the template note title as the new note title?

1 Like

Is this what you mean by your second point?

Good point, makes sense. We can use template_.

Actually the brackets {{ }} have a significance in yaml too, and are not treated as a string by our YAML parser. So, to use the same brackets, I'll need to implement a customer yaml parser and that seems too much for this feature. Probably, we can go for <% %> for v1 as you said.

1 Like

We can do it, but now with this feature the user can cutsomize the title. So, I think that this is better than using the same title.

1 Like

I might be missing something but why can't they customise the title if it's the actual template title?

1 Like

For example, They want to have the minutes for a meeting. They currently have two projects, Proejct 1 and Project 2. With this feature, they'll be able to use variables in the title and it could be dynamic.

For example,

---
project: enum(Project 1, Project 2)
note_title: Meeting Minutes - <% project %> - <% date %>

---

## Meeting Minutes
*Write notes here*

Now, when we create a new note with this template and select Project 2 say in the selector. The title would automatically become Meeting Minutes - Project 2 - 11/08/2021.

Thank for clarifying. But what if the template title is Meeting Minutes - <% project %> - <% date %>? I guess the title is not currently being processed by Handlebar but maybe it could?

1 Like

Ah, that's a nice idea! But we want to do a similar thing for tags too. How do you think we do that without creating a variable?

IMO, creating tags with titles like <% project %> would be a bit weird. What do you think?

Btw, I like this approach you suggested. In this way we'll be able to avoid using <% %> brackets and use the same handlebars style brackets i.e. {{ }}.

1 Like

Is the problem with { } a error like All collection items must start at the same column?

In the YAML parser? It actually, assumes the value as null. For. eg.

name: text
note_title: {{ name }}

The parser reads the value something like

{
  "name": "text",
  "note_title": null
}

Yes in the YAML.

I think you need to write it like:

name: text
note_title: "{{ name }}"

or

name: text
note_title: Project {{ name }} meeting 

because when the value of the option starts with an { and ends with an } I mean they think this is an Object on parsing and make the following:

{
  "name": "text",
  "note_title" {
      "name": null
  }
}
1 Like

Oh, ok. Didn't know that. Thanks for this. I'll try and see if this works.

UPDATE - It works! We can use the same {{ }} brackets.

According to me there are two points that need to be discussed before implementing this feature.

  • Using template_title and template_tags instead of note_title and note_tags and informing users that they should avoid using template_ variable names as they may become special variables in the future.
  • Should we use the actual template tags and title instead of special variables?