errbot
errbot copied to clipboard
Template file names must be unique.
Through trial and error, I have discovered that template file names must be unique.
If I have two plugins, both with their own "templates/issue.html", which "issue.html" that gets used by a given plugin seems to be random or depend on the fill order of some internal list. Naturally this causes problems because one plugin's template is not compatible with another.
I don't see this as an urgent bug in err itself, but rather a note for the documentation.
I'm labelling this as a bug, as it's not unthinkable for two plugins to use the same template names. Without having looked at the code in question, I suspect this happens because we just use a single Jinja template loader and add the template path for each plugin to it. Then we get a single loader with a big global list of paths, the order of which is simply dependent on the order in which plugins were discovered by Yapsy, the plugin system.
Long term, I think we could try to look up templates only for the plugin that the botcmd is a part of, perhaps falling back to looking across all plugins the way it does now when that isn't found (to maintain backward-compatibility).
Short term, I'll add a warning to the documentation and link back to this issue as it's not a very urgent bug and not likely to get changed soon unless someone else steps up to tackle the problem.
Depending on whether you are willing to transport the plugin path together with the template name on the function, there is no need to create different loaders. get_template accepts a parent parameter.
From the documentation I assume that plugin_dir + template subdir will make this pick up the one correct template. I'd be willing to give this a go if you are interested.
As an (maybe simpler) alternative, one could process the template path when adding it with the different botcmds and just handle the whole path.
@pendragon- sure give it a shot !
Just looked at this while working on #876 and seems by default jinja2.Environment does not use the parent argument.
Perhaps the simplest solution would be to subclass jinja2.BaseLoader (or FileSystemLoader) and have it's get_source method read a naming convention such as <plugin_dir>.<template_path> where plugin_dir is an absolute path, and template_path is relative to the plugin's templates dir.