Timing problems with creating a batch of notes. Can't get tp.hooks.on_all_templates_executed(callback_function: () => any working #1493
-
I'm having a bit of a problem getting my recurring calendar event template working. The following correctly creates the events when executed from my regular calendar event template as I intended, and it populates the metadata, but the template referred in creating the event "Calendar event recurring instance" creates a bit of text on the event note that pulls from the metadata - which is null when the template resolves.
The "recurring instance" template works if I put the metadata in manually before resolving, but when creating the note via tp.file.create_new() the order of templates resolving is wrong, and the metadata is not populated before the new note tries to resolve. As I understand it tp.hooks.on_all_templates_executed(callback_function: () => any) should work for exactly this problem, but when I use it with my metadata referencing text generation snippet in the Calendar event recurring instance - template it resolves into a blank note. I also tried using it within the loop in the above script that creates the notes, but it also failed - partly because I couldn't figure how to output text into the new note as tR += didn't work, which I kinf of figured. The "recurring instance" template works if I put the metadata in manually before resolving, but when creating the note via tp.file.create_new() the order of templates resolving is wrong, and the metadata is not populated before the new note tries to resolve. As I understand it tp.hooks.on_all_templates_executed(callback_function: () => any) should work for exactly this problem, but when I use it with my metadata referencing text generation snippet in the Calendar event recurring instance - template it resolves into a blank note. I also tried using it within the loop in the above script that creates the notes, but it also failed - partly because I couldn't figure how to output text into the new note as tR += didn't work, which I kind of figured. I've tried with wait times and hooks.on_all_templates and both:
Anyway, all help with this would be appreciated, whether on how to get tp.hooks.on_all_templates_executed(callback_function: () => any) working, or how to output text from the foreach() loop into a new note. Or just a better way to accomplish what I am trying to do. Anyway, all help with this would be appreciated, whether on how to get tp.hooks.on_all_templates_executed(callback_function: () => any) working, or how to output text from the foreach() loop into a new note. Or just a better way to accomplish what I am trying to do. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This because you are creating the files concurrently (see #1405 for another example of this). I would recommend creating the files sequentially. This will likely resolve most of the issues you're seeing. // 🔴 creating files concurrently
dates.forEach(createInstance);
// ✅ creating files sequentially
for (const date in dates) {
await createInstance(date);
} As far as the hooks module goes, I suspect you should be able to implement it like this in your provided template, if you still need it. // ...
async function createInstance(date) {
// ...
+ tp.hooks.on_all_templates_executed(async () => {
await app.fileManager.processFrontMatter(file, (frontmatter) => {
// process frontmatter...
});
+ });
} |
Beta Was this translation helpful? Give feedback.
This because you are creating the files concurrently (see #1405 for another example of this). I would recommend creating the files sequentially. This will likely resolve most of the issues you're seeing.
As far as the hooks module goes, I suspect you should be able to implement it like this in your provided template, if you still need it.
// ... async function createInstance(date) { // ... + tp.hooks.on_all_templates_executed(async () => { await app.fileManager.processFrontMatter(file…