Open 229c9cf0 opened 2 years ago
Your folder template could match on filename and then use tp.file.include
to bring in the appropriate template.
I ran into this same issue today, so decided to try if using regexes on file paths was feasible. It was. This works:
(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.
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
Has there been any movement on this? It's been over a year
Any updates on this?
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.
YYYY
/YYYY
-MM
YYYY
/YYYY
-WWW
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 #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.)README
files are probably the most common of those, I also have things likeINBOX
,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 patternsINBOX
/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 deepfolder_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