• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Best canonical place to put custom functions/logic?

#1
Sorry in advance if this is answered somewhere else or if it's a dumb question, didn't find anything in initial scans.

We'd like to add some custom functionality for things like what avatar is used in thread view. Specifically, we'd like to output a few canonical images instead of the avatars for certain tags, like a special image for a "news" tag, or one for a "video games" tag, etc.

At this point I'm relatively comfortable with making changes via template modifications - but rather than store some logic in a template (thread_list, in this case) and then potentially having to duplicate it elsewhere, seems like ideally there woudl be a good place I could put a function (with a tag name parameter, have a switch statement that returns a specific image path, or null if the avatar should be used). Then in the template itself, there could just be a basic conditional to 1) call that function, and 2) use the avatar as usual if null.

Is this a thing in XF? Is there a canonical way you'd create custom functions and then call them somehow? Or is the logic meant to be stored in each template? There's other modifications we'd like to make as well, just want to make sure we're adding code in the best places to minimalize problems later.
 
#2
Does anyone have ideas on this? Also, should I have put this question in a different section? Given the amount of add-on creators there are, I'm assuming there's a canonical way to do this - I'm not looking for a step by step walkthrough, just hopefully a place to start/section of the manual to focus on. :)
 

Mike

XenForo developer
Staff member
#3
As I assume you're talking about defining a custom template helper, the development forum is probably best.

You'd need a listener in an add-on to push function names into XenForo_Template_Helper_Core::$helperCallbacks. As an example, the Resource Manager does this in the init_dependencies event.