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

XF 2.0 Helpers in XF2?

katsulynx

Well-known member
#4
You can create a listener for the code event templater_template_pre_render with the event hint being your template (prefixed with public: or admin: respectively). There you can modify or add view parameters for that template.
 

Chris D

XenForo developer
Staff member
#5
I'm not sure that answers the question.

I actually suspect the desire is to create a Templater function which is the closest equivalent to template helpers from XF1.

If you have access to either XFMG or XFRM code I believe both of these have examples to add your own templater function.
 

[xFv]

Previously Cylent1
#6
I'm not sure that answers the question.

I actually suspect the desire is to create a Templater function which is the closest equivalent to template helpers from XF1.

If you have access to either XFMG or XFRM code I believe both of these have examples to add your own templater function.
Yes I am looking how to make template helpers for XF2.

I do not have either of those for XF2...

Anywhere else I might find an example at @Chris D?
 

Mike

XenForo developer
Staff member
#7
In the templater, you want to use the addFunction() method. You'd register the name of your templater function and the callback to use. If you look at the other templater functions, you'll see the basic arguments you'll receive (plus any arguments passed into the function in the template).

Best place to do this is in the templater_setup event.
 

[xFv]

Previously Cylent1
#8
In the templater, you want to use the addFunction() method. You'd register the name of your templater function and the callback to use. If you look at the other templater functions, you'll see the basic arguments you'll receive (plus any arguments passed into the function in the template).

Best place to do this is in the templater_setup event.
XF2 is so confusing to me with it being so new and different.

But I am looking to do this basically in XF2, where I can hook a template into a addon.
Code:
<?php
class MY_CLASSNAME
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        switch ($hookName) {
            case 'CUSTOM_HOOKNAME':
               $get_template = $template->create('MY_TEMPLATE', $template->getParams());
                   $contents = $get_template . $contents;
                   break;
        }
    }
}
I know there is probably many ways to do it, but I am wanting to stay away from template modifications.
I hope this explains a little better of what I need...
 
Last edited:

Mike

XenForo developer
Staff member
#9

[xFv]

Previously Cylent1
#10
I'm not really sure why you're trying to avoid them, but given your example, helpers/template functions aren't really appropriate.
Because I am wanting to learn more than template modifications basically so I can make better, more sophisticated addons.
I need to learn the eternals and how the backside works, but I cant find complete or detailed tutorials.
But I like to learn by disecting other addons and learning how they work, thats how I really learn!