Create a variable for my addOn

LordsKing

Active member
Hello :D

I would to create a variable for my addOn !
But I don't know how to do it :(

My variable will be : $user.elite_level

And the function elite_level will be the number of trophy points !

I'll explain :

If the user has 210 trophy points, and the elite level 4 is at 200 trophy points, In the user member card it will be show : Elite : 4

So the code for show this in the member card is :
HTML:
<dt>Elite:</dt> <dd>{$user.elite_level}</dd>

If you don't understand please report it in comment :)

Bye
 
You'll have to either override the Models that make the $user available in the template, or the User Model to have this variable always available when fetching user details.
 
Sorry,

But I don't understand.
Why Helpers are here ?

Helpers can be used in templates for example: {xen:helper richUsername, $user} will render a username with color. So you can create your own helper by following that tutorial then you can use it like that: {xen:helper elitelevel, $user.trophy_points} in your template
 
Helpers can be used in templates for example: {xen:helper richUsername, $user} will render a username with color. So you can create your own helper by following that tutorial then you can use it like that: {xen:helper elitelevel, $user.trophy_points} in your template
Oh....
Thanks :D

But how can I add the 'elitelevel' in the helper ? :)
 
Ok, so :

Is is that ?

Code:
XenForo_Template_Helper_Core::$helperCallbacks += array(
'elitelevel' => array('SimpleHelper_Helpers', 'helperEcho')
);
 
Ok, so :

Is is that ?

Code:
XenForo_Template_Helper_Core::$helperCallbacks += array(
'elitelevel' => array('SimpleHelper_Helpers', 'helperEcho')
);

you can change this too
PHP:
array('SimpleHelper_Helpers', 'helperEcho')
It an example, you can change it to whatever you want, but take a note on directory structer
 
Ok, thanks you

But that will not show the level elite according to user trophy points

You need to write your own code for that, in the tutorial he create a file Helpers.php in SimpleHelper folder an put in that
PHP:
<?php
//Our class helper (we can put any helpers in here we want)
class SimpleHelper_Helpers
{
    public static function helperEcho ($string)
    {
        //We only return the argument, dont do nothing.
        return $string;
    }
}
?>

You have to do the same

PHP:
<?php
//Our class helper (we can put any helpers in here we want)
class yourclass
{
    public static function yourfunction($points)
    {
        //$points = current user trophy points;
        // Write your code
        //$level = ......
        return $level;
    }
}
?>
 
You need to write your own code for that, in the tutorial he create a file Helpers.php in SimpleHelper folder an put in that
PHP:
<?php
//Our class helper (we can put any helpers in here we want)
class SimpleHelper_Helpers
{
    public static function helperEcho ($string)
    {
        //We only return the argument, dont do nothing.
        return $string;
    }
}
?>

You have to do the same

PHP:
<?php
//Our class helper (we can put any helpers in here we want)
class yourclass
{
    public static function yourfunction($points)
    {
        //$points = current user trophy points;
        // Write your code
        //$level = ......
        return $level;
    }
}
?>
Erf...
It's too difficult for me :/

I need to assign $level variable at each elite level ?
 
Erf...
It's too difficult for me :/

I need to assign $level variable at each elite level ?

It just a simple math, let's say 200 points = lvl 4 that mean 50 points per level and your code is
PHP:
$level = floor($points / 50);
return $level;
 
Last edited:
It just a simple math, let's say 200 points = lvl 4 that mean 50 points per level and your code is
PHP:
$level = floor($points / 50);
return $level;
Ok and it show Elite: 4 in the memeber card ?

And if it's not 50 points per level ?
Elite 3 : 180
Elite 4 :200 ?
 
Top Bottom