I've been trying to figure this out but can't seem to make any progress.
In XF1, if I wanted to add an active variable to the $visitor group, I added a Listener and then the following code:
And that worked great. But obviously in XF2, things are quite different and I haven't been able to solve this yet.
I've been working with the following as a class extension:
And "my_selection" is not being added to the available array fields.
I've gone over this quite a few times and I feel like I have a reasonable grasp on things. The sample for the "hello world" worked and that at least means that I have things set correctly on the admin side, but I'm clearly doing something wrong where when it comes to adding something into the structure to hopefully use it as $xf.visitor.my_selection, it isn't adding it for me to pull it within the template:
Needless to say, any guidance you can provide is appreciated.
In XF1, if I wanted to add an active variable to the $visitor group, I added a Listener and then the following code:
PHP:
if (!class_exists('Demo_Listener')){
class Demo_Listener {
public static function visitor_setup(XenForo_Visitor &$visitor)
{
$visitor["my_variable"] = $data_for_my_variable;
}
}
}
And that worked great. But obviously in XF2, things are quite different and I haven't been able to solve this yet.
I've been working with the following as a class extension:
PHP:
namespace AddOn;
use XF\Entity\User;
class User extends XFCP_User
{
public static function getStructure(Structure $structure)
{
// Query for $variable with data
$structure = parent::getStructure($structure);
$structure->getters['my_selection'] = ['getter' => $variable , 'cache' => true];
return $structure;
}
}
And "my_selection" is not being added to the available array fields.
I've gone over this quite a few times and I feel like I have a reasonable grasp on things. The sample for the "hello world" worked and that at least means that I have things set correctly on the admin side, but I'm clearly doing something wrong where when it comes to adding something into the structure to hopefully use it as $xf.visitor.my_selection, it isn't adding it for me to pull it within the template:
General concepts | Developer Documentation | XenForo
Developer documentation for XenForo
xenforo.com
Needless to say, any guidance you can provide is appreciated.
Last edited: