How To Use Template Hooks

Well, I suck at putting text into code :S
I know what you are saying and I understand the plan, but I can't make it without having errors :(

Any chance you can quickly write it out?

Something like this:

PHP:
public static function listen($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
    if ($hookName == 'account_wrapper' && $template->getTemplateName() == 'account_upgrades')
    {
        // blah
    }
}

I've not actually checked the code so I don't know if that's totally correct, but hopefully it's enough :)
 
Something like this:

PHP:
public static function listen($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
    if ($hookName == 'account_wrapper' && $template->getTemplateName() == 'account_upgrades')
    {
        // blah
    }
}

I've not actually checked the code so I don't know if that's totally correct, but hopefully it's enough :)
Nope... Doesn't work :(

PHP:
if($hookName == 'account_wrapper_content' && $template->getTemplateName() == 'account_upgrades') {
$content .= 'ben';
}

But I found out that the hook isn't in the account_upgrades page. It's in the account_wrapper template.
account_upgrades is a part of account_wrapper.

So this code can't work :S
 
Nope... Doesn't work :(

PHP:
if($hookName == 'account_wrapper_content' && $template->getTemplateName() == 'account_upgrades') {
$content .= 'ben';
}

But I found out that the hook isn't in the account_upgrades page. It's in the account_wrapper template.
account_upgrades is a part of account_wrapper.

So this code can't work :S

Should that be ... $contents .= "Ben" ? :)
 
If it's something as short as a string like that, single or double quotes are fine.

There are times when you may want to use double instead of single, but most often I only use single quotes.
Yeah, I know what you mean, but that isn't really the case when wanting to write Ben :P
 
Well my plan was to go buy a mac-top (yes it's word.. I just said it right :)) and set it up to be my dev computer as well as my mobile broadcasting pc because what I have heard about them being good as far as my needs go...

( that and some broadcasting equipment that I have, has software suites which absolutely suck for Win systems...and those are the ones that have software available that is windows based which sucks because the software is needed to properly interface the hardware to the pc in most cases)
...unfortunately I forgot about that plan again until reading your reply above lol.

speaking of which ...I really need to set one of those up....I have been making addons in notepad :-/ lol
 
It does, the name of the variable was what I was trying to point out! :)

It's $contents in the signature, not $content
When I was making my first addon this was an error I was having lol...one simple letter to make the world of a difference.

The only thing that matters is that the variable names match. I could do this and it would still work:

PHP:
public static function templateHook($hookName, &$puppies, array $params, XenForo_Template_Abstract $template)
{
    if ($hookName == 'navigation_visitor_tab_links1')
    {
        $puppies .= 'I love puppies!';
    }
}

Doesn't matter what it's called as long as it matches. :) That's the main thing to look at here and it's not complicated. If you're using an IDE, it will tell you when things don't line up or if there will be an error because of it.
 
what would be great is a video that takes this to the next level, using$hookParams, using search&replace, changing things in templates rather than simply adding things, dictate where in the hook to add a template, etc.
id love to be able to package up some of my template mods, such as alternate members online and disable status update from profile as addons.
 
Hey everybody.
I am learning XenForo at the Moment.
I do the same like Kier, except the variables:
Code:
<?php
class demo_listener
{
public static function templatehook ($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if (hookname=='footer_links')
{
$contents.= '<li><a href="http://www.google.com">Random Google Link</a></li>';
}
}
}
The Listener.php is available in library/demo, like Kiers example.
But in my Version, it won´t work and I see no further link.
Can anybody tell me why?

Faithfully

Maik
 
Hey James.
Thanks for your reply.
New Code is:
Code:
<?php
class demo_listener
{
public static function templatehook ($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if ($hookname=='footer_links')
{
$contents.= '<li><a href="http://www.google.com">Random Google Link</a></li>';
}
}
}

But the results are the same: Nothing....
I don´t see any change in my footer...
 
Hey James.
I am sorry for the question, now it works...
I´ve searched the mistake a lot of time, but I´ve forgotten that it will be case sensitive.
Now it works,
thank you.

Faithfully
 
Back
Top Bottom