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

Problem for add variable in template

Discussion in 'XenForo Development Discussions' started by Fred45, Jun 25, 2011.

  1. Fred45

    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
     
  2. Fred45

    Fred45 New Member

    No solution for this problem?
     
  3. Fred45

    Fred45 New Member

    Someone can help me please?
     
  4. Jeremy P

    Jeremy P Well-Known Member

    {$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}?
     
  5. Fred45

    Fred45 New Member

    In my template i have

    HTML:
    <div class="section">
                <div class="secondaryContent">
                    <h3>Test block</h3>
    {$myname}
                </div>
            </div>
    
     
  6. Fred45

    Fred45 New Member

    No solutions?
     
  7. Lawrence

    Lawrence Well-Known Member

    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);
     
  8. Fred45

    Fred45 New Member

    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 $hookParamsXenForo_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
     
  9. Fred45

    Fred45 New Member

    Up please ;)
     
  10. SheepCow

    SheepCow Well-Known Member

    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? :)
     
  11. Fred45

    Fred45 New Member

    yes i have really put {$myvar} in template, i make mistake in the copy/stick
     

Share This Page