farling42 / obsidian-import-json

Plug-in for Obsidian.md which will create Notes from JSON files
MIT License
85 stars 5 forks source link

JSON-Can Templater or QuickAdd inline code be triggered on import? #57

Closed buttonpushertv closed 8 months ago

buttonpushertv commented 8 months ago

It seems as though any inline Templater or QuickAdd code in a handlebars template is ignored during the import process.

Is there any way to allow this code to be executed on import?

I imagine it may not be called so that one of those templating processes doesn't overwrite the importer plugin's work, but it would be nice to have the ability to run inline code from those plugins on import as well.

farling42 commented 8 months ago

I'm simply creating new notes by calling this.app.vault.create (or this.app.vault.modify or this.app.vault.append when updating existing notes).

I have no idea how other add-ons/plugins decide when they do their work.

farling42 commented 8 months ago

https://github.com/SilentVoid13/Templater/discussions/1262

buttonpushertv commented 8 months ago

I do have the setting for Templater checked on: "Trigger Templater on new file creation"

So, I think that means it should be firing - at least Templater should. We'll see if they respond to your issue.

Thanks for doing that.

buttonpushertv commented 8 months ago

I did think of a smaller tweak that might be useful along the lines of the @dataRoot feature:

Could you add a variable that exposes the import path (set in the importer window near the bottom)? That should allow a helper to "see" the path and manipulate it to some degree.

Again, using my specific use case, I am creating a vault for running multiple TTRPG "worlds" or "campaigns". All of them will be stored in a sub-folder within the folder 01_Campaigns. If I could use the import path to extract that info, that would be a way to deal with some of the issues I was hoping to use Templater for.

Is that a handlebar variable that could be added?

FWIW, it may be worth considering passing an object from the importer that contained all of the values from the import dialog as an object. That would allow extraction of any of that information that might be helpful in templates (being able to make use of the prefix/suffix field data within the notes we are creating, for instance).

buttonpushertv commented 8 months ago

Also, and I should have said this earlier, thank you for the awesome work you have done on this importer! It really is a great tool and my pestering you on these little things truly comes from a place of hoping to make it even better with my input. Thanks for replying and considering implementing changes.

farling42 commented 8 months ago

The request for the sourcePath should be a separate issue. I know that I currently export SourceFilename so it might not be too difficult to extend this into a full path (depending on what aspects of the source file JS/Obsidian allow me to access).

buttonpushertv commented 8 months ago

And I'm closing this one as well. Once we hear from SilentVoid about how Templater gets triggered, we'll know if there's anything to be done & you can re-open if it's something you will pursue.

Thanks again for the replies & input.

farling42 commented 8 months ago

SilentVoid has replied to the above linked issue. Can you check it?

farling42 commented 8 months ago

It is worth noting that if you are having the JSON importer overwrite existing notes then the "create" rule won't be triggered.

buttonpushertv commented 8 months ago

Yes. the "Replace" function does not trigger it. However, creating a new set of files will trigger Templater inline code on import/initial creation. Subsequent imports need to have previous file deleted to get the Templater code to trigger again. So, with the caveat: Templater code only gets triggered on creation of non-existing files and will be ignored if replacing exiting files.