-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
Example for tp.hooks doesn't work #1243
Comments
They run in parallel, which means they're running at the same time and likely hitting a race condition. Those are two separate examples, not meant to be used together like that. If you want to run them sequentially, you can do it like this. <%*
tp.hooks.on_all_templates_executed(async () => {
// Update frontmatter after template finishes executing
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter["key"] = "value";
});
// Run a command from another plugin that modifies the current file, after Templater has updated the file
app.commands.executeCommandById("obsidian-linter:lint-file");
});
-%> |
Oops. Sadly, neither work for me (neither separate nor sequentially). |
Can you try it in the sandbox vault? Here's the steps I took to verify I didn't have anything weird on my system, worked for me.
Does it still not work for you after these steps? If it does work after these steps, there must be a setting or another plugin that is causing it to not work for you. |
I also ran into this issue and got stuck for a lot time. |
Plugin information (please complete the following information):
Describe the bug
The exact example from https://silentvoid13.github.io/Templater/internal-functions/internal-modules/hooks-module.html doesn't work, the file is not linted.
Nothing is logged in the console.
Expected behavior
The newly created file should get a
key
YAML from frontmatter andh1
andnote
YAML from linting.Screenshots
![image](https://private-user-images.githubusercontent.com/61841994/282515735-a99fa639-2fb2-427b-b42a-4325c1c0b11e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1NTcxMDAsIm5iZiI6MTcyMTU1NjgwMCwicGF0aCI6Ii82MTg0MTk5NC8yODI1MTU3MzUtYTk5ZmE2MzktMmZiMi00MjdiLWI0MmEtNDMyNWMxYzBiMTFlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUF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GVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Ny0SHIEwX2DZlAI6QYoJpuPumCcEN86pEh6ItHOiZ8M)
Config:
![image](https://private-user-images.githubusercontent.com/61841994/282517188-e643166d-3356-49f7-9b28-b00d633684fa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1NTcxMDAsIm5iZiI6MTcyMTU1NjgwMCwicGF0aCI6Ii82MTg0MTk5NC8yODI1MTcxODgtZTY0MzE2NmQtMzM1Ni00OWY3LTliMjgtYjAwZDYzMzY4NGZhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIxVDEwMTMyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTkzOTFjNmMyNDU1MWZjOWRhOWFhYzViMzkxZTUwYmJlZTY2NWNlYjA0ZTk4ZGMxNzM3ZGU3ZjcwYThhZWY0ZmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.zp4XcjoGYnCytEzXYNTGxRaoR5lAO6i1CiGa1_3v9Ro)
![image](https://private-user-images.githubusercontent.com/61841994/282517079-8a6fe657-029c-4e01-90aa-5b9c87ea3476.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1NTcxMDAsIm5iZiI6MTcyMTU1NjgwMCwicGF0aCI6Ii82MTg0MTk5NC8yODI1MTcwNzktOGE2ZmU2NTctMDI5Yy00ZTAxLTkwYWEtNWI5Yzg3ZWEzNDc2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIxVDEwMTMyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFkYjQxNjdkNzEyZWMwZmU0MjBhM2E4YjAwMDJhOTM4Y2M5ZDYwZjI1NzFlYWJjNWI4MDU2Yjc4ZmNiNDZmMGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.IknPMlQf4IgecWzpb4RQseBSnBv8QXOobrMnLQ1m_VI)
Additional context
I've had issues with linting from Templater in the past (unfixed): #948 (see comments)
The text was updated successfully, but these errors were encountered: