XF 2.0 Helpers in XF2?

[xFv]

Well-known member
As the title implies...
I am needing to know if XF2 uses helpers like XF1?
If so, how do they work?
 
You'll need to be more specific about what you're referring to with "helpers".
 
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.
 
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.
 
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?
 
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.
 
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:
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!
 
There is a complete tutorial in the development documentation which covers everything Involved to create a Portal add on.
 
Back
Top Bottom