My guess is that (tp.file.tags == "source") is always failing because you’re not comparing like objects. tp.file.tags is an array of strings, while "source" is simple string. Try using (tp.file.tags.includes("source")) instead.
Thanks @ninjineer - that makes sense. Tried that & hasn’t seemed to solve it, so think on reflection the issue may lie with my approach, as it requires the tag to be in the file already, and then inserting the template, rather than the template changing automatically by picking it up the tag, which is was hoping for. So maybe one for me to shelve and use the tp suggester instead, which i’ve recently found as a solution that doesn’t require me remembering which prefix identifier relates to which template. Thanks again for your input.
I think it all comes down to what is executed in which order, and regarding new files and templates it seems this is the order:
You trigger the new file creation
The file is created, either with “Untitled” as the file name, or if you followed a link with that suggested file name
The template is called on this newly created file, and it expands the template
You’re given control back over the file, and start inserting stuff
(Some time later) You can insert other templates…
Since you don’t have any control (disregarding prompts and suggesters from the template) before the template is expanded already, you can’t look at newly (or not) entered metadata and then decide to use the book template.
So your options as I see them are three-folded:
You use the templater options of using a given template, given that your new file is created in a given folder
You have a suggester within your template, which allows you to choose which template you should apply to the new file. This of course, needs to be at the start of your template
You have a generic template for any new file, and then after you’ve regained control over the file, you insert metadata, and then another template, which forms it according to the meta-data
Note however, that the latter option doesn’t really allow you for a full rebuild of the file, it’ll be more of an addon variant of a template. So it wouldn’t be easy to remove or alter sections already presented into the file.