XF 2.2 Edit output of "xf:username"

HomerJ

Member
Where can we edit the output of "xf:username" - which is called in lots of templates? I'd like to set output to just a plain username when the $user passed is in a particular group.

Thanks
 
The easiest way would be to set CSS for the username within the user group.

If you want to get more granular with what you can do, you could extend the XF\Template\Compiler\Tag\Username class.
 
If you want to get more granular with what you can do, you could extend the XF\Template\Compiler\Tag\Username class.
I could be wrong but I remember @Mike saying not to touch template tag classes as it will cause during upgrades?

Also, most if not all tags will always call a template function which is always located in the \XF\Template\Templater, eg: <xf:username /> will always call username_link and similarly <xf:date /> will call date_dynamic.

Now if you're wondering how to figure which method is being called for the tag then it is quite simple, you just need to open the tag class and see which function it is calling.

So if you were to be interested in figuring out what template function will <xf:captcha /> be calling, you would open the \XF\Template\Compiler\Tag\Captcha and there you will search {$compiler->templaterVariable}->func( (you can find multiple results depending on the tag) and then you find something like this:
PHP:
        return "{$compiler->templaterVariable}->func('captcha', array({$force}, {$forceVisible}))";
The first parameter that is being passed to the func() method is the template function which <xf:captcha /> or the tag you are messing around with will be calling so this case it will be captcha.
 
The easiest way would be to set CSS for the username within the user group.

If you want to get more granular with what you can do, you could extend the XF\Template\Compiler\Tag\Username class.
Ah I ought to have clarified what I meant by "plain". When the user is in a deleted category we've setup, I want the username to just be plaintext and non-hyperlinked.
 
I could be wrong but I remember @Mike saying not to touch template tag classes as it will cause during upgrades?
I do vaguely remember something like that now that you mention it, maybe it was for XF1? Either way, you could extend the Templater class and override the fnUsernameLink() method when the user is part of whatever user group you are checking for.
 
Back
Top Bottom