XF 2.0 template variable for avatar URL and profile URL

Not sure about the avatar one but thanks to @Chris D I now found this code works for linking to any users profile page. I hope it helps.

HTML:
{{ link('members', $xf.visitor) }}

You can also target specific member tabs by using a syntax similar to the one below. Be sure to replace #about with the appropriate tab.

HTML:
{{ link('members', $xf.visitor) . '#about' }}
 
Code:
$xf.visitor()->getAvatarUrl('s');

method signature

Code:
getAvatarUrl($sizeCode, $forceType = null, $canonical = false)
 
When I tried the above, I got this error message:

"The function visitor may not be called in a template. Only functions with whitelisted prefixes are allowed."

I think that was meant for using the variable in an add-on and not a template. Keep asking around and maybe someone will know.
 
I think that was meant for using the variable in an add-on and not a template. Keep asking around and maybe someone will know.
No, you don't call methods with "." in PHP. That's Java or some kind. Only thing I can think of using a "." is to concatenate a string in PHP.
The global template object $xf inherits a lot of other objects such as the current visitor. And via template syntax you can both access methods and objects through ".". Template methods, though, have to follow a naming scheme which you can find in XF\Util\Php public static function nameIndicatesReadOnly($name). visitor() does not fit the scheme, so it get's rejected.
 
No, you don't call methods with "." in PHP. That's Java or some kind. Only thing I can think of using a "." is to concatenate a string in PHP.
The global template object $xf inherits a lot of other objects such as the current visitor. And via template syntax you can both access methods and objects through ".". Template methods, though, have to follow a naming scheme which you can find in XF\Util\Php public static function nameIndicatesReadOnly($name). visitor() does not fit the scheme, so it get's rejected.

If your referring to the code above that is for the profile URL, I got that code directly from @Chris D. He's asking for template variables. Not for add-on functionality. And yes I know it's used to join 2 strings. But for the profile URL the code is correct. But it seems you agree from your post. Not sure what your trying to say or if your just pointing that out but thanks I guess.
 
Yes, me too. It's the explanation why it's not meant to be used in an addon, but a template and why @XFConvert got the error using that code from @ludak . There's a good difference between PHP and XF template syntax, although similar.
 
Top Bottom