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

Notes are created in parent directory instead of specified directory #1332

Closed
alexjbarnes opened this issue Mar 4, 2024 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@alexjbarnes
Copy link

Plugin information (please complete the following information):

  • OS: Ubuntu 22.04
  • Templater version: 2.2.2
  • Obsidian version: 1.5.3
  • Templater settings: Template folder location: "Templates/"

Describe the bug
When using versions greater 2.1.4, when using templater to create a new note from within metabind it creates the note in the parent folder rather than the specified folder. For the example below, notes are created in the journal folder in version 2.1.4 and in the DB folder in versions 2.2.0 and above. I have tried adding an extra / to the end of path but get error folder not found.
Apologies if this is an issue with how metabind integrates with templater, i could just see changes in getting paths within templater recent releases. And downgrading to 2.1.4 fixes the issue.

label: Create New Entry
hidden: false
class: ""
tooltip: ""
id: ""
style: primary
actions:
  - type: templaterCreateNote
    templateFile: Templates/journal_template.md
    folderPath: Work/Organiser/DB/Journal
    fileName: ""
    openNote: true

Expected behavior
Notes to be created within the specified directory.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@alexjbarnes alexjbarnes added the bug Something isn't working label Mar 4, 2024
@Zachatoo
Copy link
Collaborator

Zachatoo commented Mar 4, 2024

You're setting the file name to an empty string, what are you expecting the file name to be when the file is created?

fileName: ""

@alexjbarnes
Copy link
Author

Yes sorry I should of mentioned that, I leave file name blank, then inside the journal_template there is a templater block that renames it to todays date. I've copied that in below. I'm not sure that's the issue, as it creates the new note with today's date fine, just at the wrong level in the directorys.

<% tp.file.rename( tp.date.now("DD-MM-YYYY") ) %>

@Zachatoo
Copy link
Collaborator

Zachatoo commented Mar 4, 2024

What should the file name be before your template renames it? That's where I'm a bit lost, I need to know what it was doing before.

@alexjbarnes
Copy link
Author

I don't currently set it, as it is immediately renamed. So I'm guessing it is either empty string or defaults to untitled.

@alexjbarnes
Copy link
Author

Yes I just tried it without the rename command in the template and it just gets set to untitled.
I have just tested it with setting a default name for the note instead of an empty name and it works fine in latest version. So guessing it's just a weird edge case of having no file name messes up the path creation. Happy to close this issue if you want, and I'll just add file names into my buttons.
Thanks for your help.

Zachatoo added a commit that referenced this issue Mar 5, 2024
@Zachatoo
Copy link
Collaborator

Zachatoo commented Mar 5, 2024

I was able to encounter the same issue using just Templater and tp.file.create_new(). Here's the equivalent I tested with.

<%*
const templateFile = tp.file.find_tfile("Templates/journal_template.md");
const folder = app.vault.getAbstractFileByPath("Work/Organiser/DB/Journal");
const fileName = "";
await tp.file.create_new(templateFile, fileName, true, folder);
-%>

I have fixed this in 2.2.3, I believe this will also resolve the issue you were facing with metabind!

@alexjbarnes
Copy link
Author

Brilliant thank you 👍

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