Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Obsidian 1.8.5] app.fileManager.processFrontMatter stop working #1540

Closed
Mara-Li opened this issue Feb 8, 2025 · 4 comments
Closed

[Obsidian 1.8.5] app.fileManager.processFrontMatter stop working #1540

Mara-Li opened this issue Feb 8, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@Mara-Li
Copy link

Mara-Li commented Feb 8, 2025

Plugin Information

  • OS: Windows 11
  • Templater version: 2.9.3
  • Obsidian version: 1.8.5
  • Templater settings: Default

Describe the Bug

When using the following code:

<%* 
	const file = tp.file.find_tfile(tp.file.title); 
	await tp.app.fileManager.processFrontMatter(file, (frontmatter) => {
		frontmatter["key"] = "U"; 
	}); 
%>

The frontmatter does not get updated. Instead, it appears to be modified and then immediately reverted, as if Obsidian restores the file's original contents.

Expected Behavior

The frontmatter should be updated with the new key-value pair.

Screenshots

Screen recording

Additional Context

The issue is reproducible in Obsidian's sandbox mode.

@Mara-Li Mara-Li added the bug Something isn't working label Feb 8, 2025
@Mara-Li Mara-Li changed the title ProcessFrontmatter stop workings [Obsidian 1.8.5] app.fileManager.processFrontMatter stop working Feb 9, 2025
@Zachatoo
Copy link
Collaborator

I can reproduce when using the "replace templates in the active file" command, but not the "open insert template modal" command, which is the more commonly used command. Are you seeing the same? Do you have a use case for "replace template in the active file" outside of testing?

I am also on Obsidian 1.8.5, Templater 2.9.3.

@Mara-Li
Copy link
Author

Mara-Li commented Feb 11, 2025

I use mostly "replace templates in the active file" than open insert template modal :'). I have even a quick shortcuts for it, so i can write template and quick replace the text.

@Zachatoo
Copy link
Collaborator

In that case, I can recommend the following.

<%* 
const file = tp.file.find_tfile(tp.file.title); 
await tp.hooks.on_all_templates_executed(async () => {
  await tp.app.fileManager.processFrontMatter(file, (frontmatter) => {
    frontmatter["key"] = "T"; 
  });
});
-%>

Let me know if that doesn't work and I'm happy to explore more options with you!

Closing since I don't expect we'll be able to fix the original issue, and will instead rely on this workaround.

@Zachatoo Zachatoo closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2025
@Mara-Li
Copy link
Author

Mara-Li commented Feb 13, 2025

Thank you! It was what I have done when discovering the hook :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants