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

Template Hook Question

Discussion in 'XenForo Development Discussions' started by Itworx4me, Mar 29, 2011.

  1. Itworx4me

    Itworx4me Well-Known Member

    I am trying to add a bigfooter to the bottom of my site using templateHook. Everything seems to look ok but the footer doesn't show at the bottom of the site. I setup the Code Event Listener. Will someone take a look and tell me if the code looks correct?

    PHP:
    <?php

    class RPMfooter_Listener
    {
        public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if(
    $hookName == 'footer')
            {
                
    $content .= $template->create('RPM_bigfooter');
            }
        }
    }
    Thanks,
    Itworx4me
     
  2. Arik

    Arik Well-Known Member

    You're passing a variable $contents into the function. Then, within the function, you're modifying the variable $content.
     
  3. Itworx4me

    Itworx4me Well-Known Member

    I was just following Kier video instructions. So how should the code look?

    Thanks,
    Itworx4me
     
  4. Arik

    Arik Well-Known Member

    Ha! So, that's what's going on...You're the second person I've seen whose made this mistake.

    Code:
    $contents .= $template->create('RPM_bigfooter');
     
    Umit likes this.
  5. Itworx4me

    Itworx4me Well-Known Member

    Very weird because in his video it shows $content not $contents. Wonder why is worked then...lol
     
  6. Arik

    Arik Well-Known Member

    The method signature that he copied out of his admin is different than what's in mine. Likely yours, too, given what you coded.
     
  7. Itworx4me

    Itworx4me Well-Known Member

    Thank you Arik....After changing $content to $contents it worked. Appreciate your help :)

    Itworx4me
     
    Umit and Arik like this.
  8. Itworx4me

    Itworx4me Well-Known Member

    I tried adding this to the listener:
    PHP:
    $contents .= $template->create('RPM_bigfooter'$template->getParam);
    And I get this error:
    Code:
    Template Errors: PAGE_CONTAINER
    Argument 2 passed to XenForo_Template_Abstract::create() must be an array, null given, called in /home/library/RPMfooter/Listener.php on line 17 and defined in /home/library/XenForo/Template/Abstract.php, line 102:
    101: ';
    102: $__compilerVar4 = '';
    103: $__compilerVar4 .= '
    Argument 2 passed to XenForo_Template_Abstract::__construct() must be an array, null given, called in /home/library/XenForo/Template/Abstract.php on line 105 and defined in /home/library/XenForo/Template/Abstract.php, line 80:
    79: '0' => XenForo_Template_Helper_Core::callHelper('stripHtml', array(
    80: '0' => $pageDescription['content']
    81: )),
    Argument 2 passed to RPMfooter_Listener::templateCreate() must be an array, null given in /home/library/RPMfooter/Listener.php, line 5:
    4: <head>
    5: ';
    6: $__compilerVar1 = '';
    Following Kier's video again ....lol

    Can someone let me know what the fix is?

    Thanks,
    Itworx4me
     
  9. Arik

    Arik Well-Known Member

    PHP:
    $template->getParams()
    getParams is a function.
     
  10. Itworx4me

    Itworx4me Well-Known Member

    Thanks Arik for the help. I think Kier needs to redo his video on Template Hooks. It would be helpful to get the right code to get the hook system to work correctly.

    Thanks again,
    Itworx4me
     
    Arik likes this.
  11. Arik

    Arik Well-Known Member

    If you've got it working, might want to post the code so that others who may have issues have someplace to look.
     
    Umit likes this.
  12. Itworx4me

    Itworx4me Well-Known Member

    Here is the code that I used to get the TemplateHook to work:

    PHP:
    <?php

    class RPMfooter_Listener
    {
        public static function 
    templateCreate($templateName, array &$paramsXenForo_Template_Abstract $template)
        {
            if (
    $templateName == 'PAGE_CONTAINER')
            {
                
    $template->preloadTemplate('RPM_bigfooter');
            }
        }

        public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if(
    $hookName == 'footer')
            {
                
    $contents .= $template->create('RPM_bigfooter'$template->getParams());
            }
        }
    }
     

Share This Page