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

Use style by gender or usergroup

PoLiZe

Well-known member
#1
Hi people of xf, i'm needing that..


I need a script for AutoChoose the style per gender or usergroup..

so, if the gender are male, styleid = 1 and female = 2

How i can make that and where?
 

PoLiZe

Well-known member
#2
Now i have that:

PHP:
$visitor = XenForo_Visitor::getInstance();
		if ($visitor['gender'] == "male")
			{
				$dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
				$dw->setExistingData($visitor['user_id']);
				$dw->set('style_id', '3');
				$dw->save();
			}
		if ($visitor['gender'] == "female")
			{
				$dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
				$dw->setExistingData($visitor['user_id']);
				$dw->set('style_id', '1');
				$dw->save();
			}
but dont work, i have that in controllerpublic index.

and i put on misc and too, dont work!.
 

Shadab

Well-known member
#4
You could create a new event listener, attached to the "front_controller_pre_view" event;
and change the selected style Id dynamically:

(Untested)
PHP:
if (!is_subclass_of($controllerResponse->controllerName, 'XenForo_ControllerPublic_Abstract'))
{
	return;
}

$visitor = XenForo_Visitor::getInstance();

switch ($visitor['gender'])
{
	case 'male':
		$styleId = 1;
		break;

	case 'female':
		$styleId = 2;
		break;

	default:
		$styleId = 3;
		break;
}

$fc->getDependencies()->mergeViewStateChanges(array('styleId' => $styleId));
 

Shadab

Well-known member
#6
Nah. You don't need to edit any core php files.

Create a static method in your own class, for example, in /library/Polize/Addon.php with the code given in post #4. Then add a new event listener via Admin Panel for the "front_controller_pre_view" event and set its callback to the static method you created.

Create a new event listener, attached to the "front_controller_pre_view" event.