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

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:
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?
Because only then it will direct you to the tab when you click on the link.
2. Step 14 - Lets use them!
I want to see the data inside $content before render, so i put
Code:
var_dump($content)
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?
$contents

3. Step 15 - Pre loading templates
If we do not preload templates, it can still work. so what is the benefit to preload templates?

Preloading templates allows XenForo to keep the template in cache, so it doesn't have to fetch the template over and over again.
 
  • Like
Reactions: LPH
Hi tyteen4a03, thanks for your answers.

For question 1:
Because only then it will direct you to the tab when you click on the link.
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.
 
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.
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?
 
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)
 
Try appending the hook name before the var_dump() output to see what case the var_dump() was referring to.
 
Back
Top Bottom