Today I ran into a weird problem when one of my listener worked incorrectly. After quite a lot of time, I have found the problem: another addon changed the $templateName in its listener for `template_create`. I'm not sure why XenForo passes the $templateName as reference but I'm sure that: YOU SHOULD NOT CHANGE IT IN YOUR LISTENERS.
Let me explain why
- You will break other `template_create` listeners. The listener for `template_create` relies on $templateName to do its job (mostly to preload templates, at least for me). And boom, you change it to something else, no preload can be done anymore... That's a waste of resources. Okie, you can change your priority to minimize the problem but... read on
- You will break YOUR other `template_create` listeners. Imagine 2 of your addons want to change the $templateName. It's obvious that only 1 of them will succeed. Well, congratulation, 50% of your addons doesn't work.
- You will break all `template_post_render` listener. I'm not sure how everybody does it but on my listeners for `template_post_render`, I always rely on $templateName to decide what to do. Well, if it was changed, nothing will be done. Thank you very much for that
Thank you for reading. Gotta find a workaround for my problem now