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

questions about 'insert tabs in profile page ' tutorial part 1

Discussion in 'XenForo Development Discussions' started by typostudy, Jun 4, 2013.

  1. typostudy

    typostudy Member

    I am reading this tutorial: http://xenforo.com/community/thread...nsert-tabs-in-profile-page-using-hooks.21205/, but got some questions:

    Questions:
    1. Step 6 - Our file Listener.php
    Code:
    <li><a href="{$requestPaths.requestUri}#ourTab">Our Tab</a></li>
    why put
    Code:
    #ourTab
    here?

    2. Step 14 - Lets use them!
    I want to see the data inside $content before render, so i put
    Code:
    var_dump($contents)
    here:
    Code:
    case 'member_view_tabs_heading':
      //Get our template!
      $ourTemplate = $template->create('newProfileTab_ourTab', $template->getParams());
      //Render
      $rendered = $ourTemplate->render();var_dump($contents);
      //Put the rendered template in the contents.
      $contents .= $rendered;
      break;
    And i got result: string '' (length=0). But if i put var_dump($contents); before swicth(), i can get lots of output.
    so why?

    3. Step 15 - Pre loading templates
    If we do not preload templates, it can still work. so what is the benefit to preload templates?
     
    Last edited: Jun 4, 2013
  2. tyteen4a03

    tyteen4a03 Well-Known Member

    Because only then it will direct you to the tab when you click on the link.
    $contents

    Preloading templates allows XenForo to keep the template in cache, so it doesn't have to fetch the template over and over again.
     
    LPH likes this.
  3. typostudy

    typostudy Member

    Hi tyteen4a03, thanks for your answers.

    For question 1:
    if I put '#ourTab', the link of the tab is something like xenforo/members/admin.1/#ourTab,
    If I do not put '#ourTab', the link is xenforo/members/admin.1/,
    In both situations, when I click the tab, it shows the same page, and the url of the page is xenforo/members/admin.1/,
    so what is the difference with and without '#ourTab'?

    For question 2:
    Actually I put it is var_dump($contents); if u see my codes above.
     
  4. tyteen4a03

    tyteen4a03 Well-Known Member

    1. That stands for anchor, which is used to jump to a specific location in the same page. See this for more details.
    2. Not sure what you are doing. Full code please?
     
  5. typostudy

    typostudy Member

    Hi tyteen4a03, thanks.
    For question 2, the full code is:
    Code:
    <?php
    class newProfileTabs_Listener
    {
        public static function template_hook ($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
        {
            //Swiiitch!
            switch ($hookName) //the hookname
            {
                //first template hook
                case 'member_view_tabs_heading':
                    //Get our template!
                    $ourTemplate = $template->create('newProfileTab_ourTab', $template->getParams());
                    //Render
                    $rendered = $ourTemplate->render();
                    //Put the rendered template in the contents.
                    $contents .= $rendered;
                    break;
                //second template hook
                case 'member_view_tabs_content':
                    //Get our template!
                    $ourTemplate = $template->create('newProfileTab_ourTab_content', $template->getParams());
                    //Render
                    $rendered = $ourTemplate->render();
                    //Put the rendered template in the contents.
                    $contents .= $rendered;
                    break;
            }
        }
    }
    ?>
    I just wonder, if i put var_dump($contents); before switch(), I can get output, but if i put var_dump($contents); before $contents.=$rendered; the output is:string '' (length=0)
     
  6. tyteen4a03

    tyteen4a03 Well-Known Member

    Try appending the hook name before the var_dump() output to see what case the var_dump() was referring to.
     
  7. typostudy

    typostudy Member

    sorry, not quite understand, how to do this?
     
  8. tyteen4a03

    tyteen4a03 Well-Known Member

    echo ("hook1 var_dump: ". var_dump($contents))
     

Share This Page