How To Use Template Hooks

Kier

XenForo developer
Staff member
Following the introduction of the mega footer here on XenForo.com, which I said was included using template hooks and requires no direct template edits, this video tutorial talks about template hooks, what they are and why you would want to use them.

It then goes on with a few examples to get you started.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
http://vimeo.com/20701582Or view on Vimeo
 
Wow your a fast coder ;)
You should see Mike
notworthy.png
 
I agree. At the risk of sounding creepy. I love watching these just to see how fluid the thought process is when explaining what each function is and why he is typing what he is typing. It's like watching an artist painting.
and on that note....

Just finished with another round of watching the video...this one is particularly great at explaining what goes where and WHY and I am confident that in 10 minutes when my coffee is gone..I will have no problem first time around implementing this.

Which brings me to an awesome revelation...
 
  • Like
Reactions: Dan
While I love the concept of template hooks, there are some concerns that I would really like to have addressed:

1. I would like a way to "expose" which templates are being modified by template hooks, this might sound simple now, but after I start installing dozens of plugins, finding out which addon modifies what could turn into a nightmare, really fast, really soon. I could always go and check what listeners are being applied, then check that listener class individually ... This sounds like it could lead to countless hours of debugging

2. Is it possible to modify the template at compilation time, instead of at generation time? Right now it seems that it is modified at runtime, appending or modifying contents, but I would also like to be able to, say, modify the actual template definition. This is a little different in the sense that the hook would be applied once when the add-on is compiled and everytime the templates are recompiled. Could we maybe have both?

3. I feel a little uneasy by the feeling that if there are 100 hooks in templates, and I have a listener, that same listener is called for the 100 hooks.. is that the case? so, for example, if I want to modify a fragment of thread_view, I add a template hook and suddenly that hook is called for every single template on the site everywhere? home - called, members - called, etc - called .. Maybe I am over-obsesive and the "switch ($hookName)" is so unexpensive this is not a problem. Please give me reassurance.
 
  1. This is not a perfect system. We'd like to do something more extensive in the future, but for now this at least does the job of allowing edits without editing (if you know what I mean)
  2. No, this has to be done at runtime with the current approach
  3. switch() statements are very, very cheap.
 
This is probably a stupid question, but I'm trying to follow along with the vimeo presentation, and I don't seem to have a paragraph that displays the "Callback signature" on the "Code Event Listener Editor" page, like it does in Kier's vimeo production.Why would that be?

Not a big deal, it's easy enough to copy from the list of Arguments on the list, but just curious.
 
Back
Top Bottom