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

Is It Possible to Override <xen:username /> At All?

Discussion in 'XenForo Development Discussions' started by James, Aug 6, 2011.

  1. James

    James Well-Known Member

    <xen:username /> directly calls XenForo_Template_Helper_Core::userNameHtml() and there doesn't seem to be a hook that allows me to either:
    a) extend the compiler and specify a new callback
    b) extend the XenForo_Template_Helper_Core::userNameHtml() to specify a new callback

    I know that in 1.1 the <xen:username /> is called via callHelper() for things like this, but is it possible at present?
  2. Fuhrmann

    Fuhrmann Well-Known Member

    Would like to know this too.
  3. Basilio

    Basilio Member

    No, as of 1.1 it is not possible. This helper is called from XenForo_Template_Helper_Core class, which is not extendable.
    There is a discussion here - hopefully, this will be added in one of the future releases (you might actually help if you also post in that thread and ask for them to do it).
    Meanwhile, as of now the only possibility to overide the helper is to hack into the source core of XenForo_Template_Helper_Core. However, there are a few limitations to that - one of them is the simple fact that some of the templates use {$user.username} instead of <xen:username /> - there are not too many of them, but still that limits the usefulness of hacking into username helper code.
  4. xfrocks

    xfrocks Well-Known Member

    You can by doing something like this.

    In the init_dependencies listener

    XenForo_Template_Helper_Core::$helperCallbacks['username'] = array('MyAddon_Template_Helper''helperUsername');
    Then in your MyAddon_Template_Helper:

    class MyAddon_Template_Helper {
    protected static 
    $_helperUsernameOriginalCallback false;
    public static function 
    setHelperUsernameOriginalCallback($callback) {
    if (
    $callback[0] == 'self'$callback[0] = 'XenForo_Template_Helper_Core';
    self::$_helperUsernameOriginalCallback $callback;
    public static function 
    helperUsername(array $user$class ''$rich false) {
    $user['username'] = 'some other interesting name';
    call_user_func(self::$_helperUsernameOriginalCallback $user$class$rich);
    This code is not tested though :p
    Fuhrmann and Basilio like this.
  5. Basilio

    Basilio Member

    Tested. It works. Thank you!

    PS Still there is a number of templates that use {$user.username} instead of the helper - they have to be updated somehow.

Share This Page