Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Add support for Templater templates in new notes#889

Open
H3mul wants to merge 2 commits intoobsmd-projects:mainfrom
H3mul:templater-templates-pr-42
Open

Add support for Templater templates in new notes#889
H3mul wants to merge 2 commits intoobsmd-projects:mainfrom
H3mul:templater-templates-pr-42

Conversation

@H3mul
Copy link
Contributor

@H3mul H3mul commented Jun 3, 2024

PR for #42, since that issue hasn't had any activity

In addition to the proposal, the project setting disappears from the menu if Templater is disabled/not installed, as requested

image

@H3mul H3mul changed the title Templater templates pr 42 Add support for Templater templates in new notes Jun 3, 2024
@Acylation Acylation added kind/feature New feature request area/integrations Issues related to integrating other projects with Projects. area/templates Issues related to templates labels Jun 3, 2024
@Acylation
Copy link
Collaborator

Acylation commented Jun 3, 2024

Thank you so much on contributing! I will review this and add zh-cn translation in a day or two.

A quick question, can it be a plugin-level config so that users can always call templater with one setup? To achieve this we need to ensure that templater would skip empty/plain templates and let Projects handle it. Also in the origin issue, bon proposed a template-level enable mark. It seems that the config level should be carefully designed.

const tagSet: Set<string> = new Set(
templateTags.concat(record.values["tags"])
);
record.values["tags"] = [...tagSet];
Copy link
Collaborator

@Acylation Acylation Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick explaination on L117-L131.

There's a certain case that, when user create a new note under a tag-sourced project, the tag is expected to added to the frontmatter automatically. It's neccessary to uniquify the tags field if there's already one listed in the template. See more in #646

So in the useTemplater branch we hope it can act the same.

Copy link
Contributor Author

@H3mul H3mul Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I assumed this was part of the legacy templating process and left it untouched

Out of curiousity, is there any reason not to move this handling to doUpdateRecord()? This tagging feature seems similar to assigning the correct frontmatter properties to notes after creation (eg, when creating the note from a board that's tracking a particular property value) which is already handled there.

If this seems ok to you I'll make this refactor - seems cleaner to me anyway: we render the a new note file with/without template and then we edit its frontmatter with correct properties and tags in doUpdateRecord().

@H3mul
Copy link
Contributor Author

H3mul commented Jun 4, 2024

Huh... during testing, I noticed Templater has a setting for automatically picking up new files and rendering templates transparently - technically this fulfills #42 as is :) it satisfies my use-case

image

The only reason I see to go forward with the changes in this PR is if someone wants to use Templater but doesn't want it to run on all new files for some reason. I'll be happy to continue working on this code if you think its enough of a use-case. Feel free to close this and #42 otherwise

@bjonnh
Copy link

bjonnh commented Oct 12, 2024

Yes please follow up on this PR, I had to enable the option in templater but I would like to not have it enabled as I am processing files from outside (and Projects is the only reason I did so).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/integrations Issues related to integrating other projects with Projects. area/templates Issues related to templates kind/feature New feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants