How does Code Event Listener: template_create work?

Jaxel

Well-known member
I'm trying to set up a template_create listener... template_create
Called whenever the template object constructor is called. You may use this event to modify the name of the template being called, to modify the params being passed to the template, or to pre-load additional templates as needed.
Basically, whenever a specific template is called, I want to attach an additional template immediately afterwards. If there was a hook, I could attach it to the $contents; but since its not a hook, and there is no $contents, I dont know how to attach it.
Code:
    public static function template_create($templateName, array &$params, XenForo_Template_Abstract $template)
    {
        switch ($templateName)
        {
            case 'node_category_level_2':
            case 'node_forum_level_2':
            case 'node_link_level_2':
            case 'node_page_level_2':
        }
    }
 
I'm an idiot... template_create is used for caching isn't it... and I can't do this, can I?
 
Although Mike was talking about template hooks, this explanation is true for the "template_create" code event as well.
A post-render event? Not particularly hard, though that's probably too high level to make any useful changes. You're only going to get the final output, and that would be something like this entire thread view page. As template includes are resolved at compile time, the individual post templates aren't evaluated separately.
 
Yeah, there are no contents - it's in the constructor. You're looking for template_post_render (I believe that's the name).
 
Although Mike was talking about template hooks, this explanation is true for the "template_create" code event as well.
The particular templates in his code are actually created in the code, so they will have individual create/render calls. Generally what you quoted/I said is true though.
 
Top Bottom