I suppose the key difference between extension and replacement is the function return. I am returning a template object, instead of a string. So that means I am replacing that function completely. And my question is what is the best approach to provide extensibility for other developers in that way that they won't replace my function completely. How should I design my add-on to make it extensible and how should other developers use that properly (so that their code still works without my add-on)?It sort of depends what you mean. If you're extending the function (via a class extension), then other developer's extensions would apply as well. If you're replacing it, then that is likely to only allow one add-on's implementation to really be running at a time.
If you can explain what you mean in more detail, that may allow me to understand what you're after more.
But that's the whole idea behind an add-on to extend current implementation of that functionality. How can I useWell there isn't a ton you can do per se -- I mean, you are effectively just replacing our implementation, right? The only thing I'd recommend is that you return a string as that's what the method is expected to return (and the default version does).
Templater functions are reasonably low level, so it will always be difficult for multiple add-ons to change the same one in compatible ways, especially if you're overriding the main function itself (fnAvatar in this case), given that it's just returning HTML.
renderTemplate() and return a string at the same time? Should I do it like this to preserve compatibility with other add-ons?$renderedTemplate = $this->renderTemplate("public:avatar", $viewParams);
return strval($renderedTemplate);
We use essential cookies to make this site work, and optional cookies to enhance your experience.