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

allow folder templates to match on file name #471

Closed
229c9cf0 opened this issue Dec 13, 2021 · 6 comments
Closed

allow folder templates to match on file name #471

229c9cf0 opened this issue Dec 13, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@229c9cf0
Copy link

Problem
It's possible to apply per-folder templates, but there are often different styles of files combined in a folder that differ by file name pattern. Some examples:

  • logs / journals can have monthly, weekly, and daily notes, so the patterns might be e.g.

    • Log/YYYY/YYYY-MM
    • Log/YYYY/YYYY-WWW
    • Log/YYYY/MM/YYYY-MM-DD

    The current capabilities would only allow a folder template for Log, which clearly isn't specific enough. Even folder patterns as suggested in Support for wildcards when adding Folder Templates #418 would not solve this (since monthly and weekly notes are in the same directory), but being able to match the combination of folder and file pattern as e.g. folder /Log and file pattern ????-??, ????-W??, or ????-??-?? would fully identify the type (monthly / weekly / daily note.)

  • In projects, data collections, etc., beside the actual data that should match the folder-specific template, there's often also metadata that should match global metadata templates. README files are probably the most common of those, I also have things like INBOX, TODO, STATS, ... Ideally, they they all have exactly the same structure, no matter where in the tree they are. So here the folder pattern would just be / and the file patterns INBOX / README / ..., i.e. no matter where in the tree, this template should be used for this particular file.

Suggested solution
Extend the folder templates list from (folder, template) to (folder_pattern, file_pattern?, template) (this would subsume #418).

If present, a file_pattern match should be stronger than even a deep folder_pattern match, to allow global structure across all folders. (I think the end result is two layers: (1) both file + folder pattern match, pick the deepest of these. (2) no file pattern and only the folder pattern matches, pick the deepest as done currently.)

Specific flavour of pattern doesn't matter. Glob-style would be nice (no need to escape / in paths), but plain regex works too. (Glob implementations exist - e.g. 'minimatch' - but I can't assess whether they're any good.)

As a first step, even allowing only exact matches on file names (no patterns at all) would already solve many problems.

Alternatives?
Not aware of any, apart from manual workarounds.

Additional context
n/a

@229c9cf0 229c9cf0 added the enhancement New feature or request label Dec 13, 2021
@shabegom
Copy link
Collaborator

Your folder template could match on filename and then use tp.file.include to bring in the appropriate template.

@harmtemolder
Copy link
Contributor

I ran into this same issue today, so decided to try if using regexes on file paths was feasible. It was. This works:

image

(master...harmtemolder:obsidian-templater:master)

This is nowhere near ready for a pull request, but I will work towards one.

@harmtemolder
Copy link
Contributor

I'm thinking about a toggle to switch between the current folder templates and these file regexes, because I understand that regexes are not for everyone

@tomatau
Copy link

tomatau commented Jan 23, 2024

Has there been any movement on this? It's been over a year

@rjmoggach
Copy link

Any updates on this?

Zachatoo added a commit that referenced this issue Oct 1, 2024
Merge pull request #974 from harmtemolder/master

refs: #471
Zachatoo added a commit that referenced this issue Oct 1, 2024
@Zachatoo
Copy link
Collaborator

Zachatoo commented Oct 1, 2024

This has been added in 2.7.3, thanks to @harmtemolder !

@Zachatoo Zachatoo closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants