SilentVoid13 / Templater

A template plugin for obsidian
https://silentvoid13.github.io/Templater
GNU Affero General Public License v3.0
3.14k stars 188 forks source link

allow folder templates to match on file name #471

Open 229c9cf0 opened 2 years ago

229c9cf0 commented 2 years ago

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:

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

shabegom commented 2 years ago

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

harmtemolder commented 1 year ago

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

image

(https://github.com/SilentVoid13/Templater/compare/master...harmtemolder:obsidian-templater:master)

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

harmtemolder commented 1 year ago

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 commented 7 months ago

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

rjmoggach commented 5 months ago

Any updates on this?