Problem for add variable in template

Fred45

New member
Hello guys, in first time sorry for my bad english, i am french :)
I am new on xenforo and i have one problem of developpement, i have create a new extension and i have configurate the event listener.
I have added one on load_class_controller and one on templatehook
My template appears good but my variable in template return nothing
In my controller file i have my public function actionIndex() who contains :

PHP:
public function actionIndex()
{
$response = parent::actionIndex();
$response->params += array('myvar' => 'test');
return $response;
}


but I tried to copy in template {$myvar} and {xen:raw $myvar} and nothing
Someone can help me?
Thanks
 
{$myvar} would work in the template that action is responding with, as long as it's returning a view. Where are you trying to use {$myvar}?
 
In my template i have

HTML:
<div class="section">
            <div class="secondaryContent">
                <h3>Test block</h3>
{$myname}
            </div>
        </div>
 
How are you using the template hook listener, to load your own custom template that will contain the data contained in $myname?

If so, this will work (in your template hook listener):

PHP:
                    $params = array(
                        'myname' => $myname
                    );

                    $contents .= $template->create('name_of_your_custom_template', $params);

Another way:

PHP:
                    $hooksearch = '<!-- block: forum_stats -->';

                    $hookreplace = $hooksearch.$template->create('name_of_your_custom_template',$params)->render();
                    $contents = str_replace($hooksearch, $hookreplace, $contents);
 
In my Listener.php i have

PHP:
    public static function listen($class, array &$extend)
    {
        if ($class == 'XenForo_ControllerPublic_Index'){
            $extend[] = 'xenFrench_LegendeGroupes_Controlleur';
        }
    }

    public static function templateHookAffiche($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        $options = XenForo_Application::get('options');
        if ($options->xenFrench_legende_activation)
        {
            if($hookName == 'ad_sidebar_below_visitor_panel')
            {
                $contents .= $template->create('xenFrench_legende_forumhome', $template->getParams());
            }
        }
    }

and in my Controlleur.php i have

PHP:
class xenFrench_LegendeGroupes_Controlleur extends XFCP_xenFrench_LegendeGroupes_Controlleur
{
public function actionIndex()
{
$response = parent::actionIndex();
$response->params += array('myvar' => 'test');
return $response;
}
}

When I use print_r($response) in Controlleur file, the array appears well.
Thanks
 
Earlier you said you used {$myname} in the template, you have set myvar in the source code, do you really have {$myvar} in the template? Is it that simple? :)
 
Top Bottom