How To Use Template Hooks

Source code changes?
SINCE WHEN!
Watch the video and you might understand. There are a lot of stuff that has changed since Kier made that video. Would be nice of him to update it because it doesn't work as it is now. If you follow what he does exactly it won't work.
 
The video illustrates how to use the system. It is not intended to be a parrot-fashion cut and paste exercise of providing code for people to use. If people don't understand that function signatures need to match the content of the functions they are writing, they probably shouldn't be writing code at all.

I see no need to update the video.
 
The video illustrates how to use the system. It is not intended to be a parrot-fashion cut and paste exercise of providing code for people to use. If people don't understand that function signatures need to match the content of the functions they are writing, they probably shouldn't be writing code at all.

I see no need to update the video.

Kier, some of us have no or little knowledge to coding, but Xenforo seem like an easy system to make us try to learn with it. I personally started learning to write some coding back in the day of IRC, making script for some IRC clients such as mIRC, a bit of EGGDROP(TCL), Now I know the very basic of html/css/php and a little mysql, but never got to serious with it and never continue to develop my coding skills :(

Now Xenforo made me hit the tutorials, and try to learn some more and maybe in the future develop some small mod for myself and maybe who know others on the Xenforo community. So IMO I think you comment above was a bit harsh :(! I agree, no need to upgrade the video, but maybe just a note on the first post noting that the tutorial/walk through process code may change as Xenforo develops and that we may need to tweak it ourself?

I personally know that the 'variables' need to match, but since I'm following a video to walk me through a product and I'm following step by step, I would not expect that type of errors as if I was spitting everything out of my head and therefore, did not really cared to look for that.

Just my 2 cents!

I ask you or brogan to delete this post after if you would like so the thread doesn't keep going of track.. ;)
 
Watch the video and you might understand. There are a lot of stuff that has changed since Kier made that video. Would be nice of him to update it because it doesn't work as it is now. If you follow what he does exactly it won't work.
I just looked and saw Kier copying the code from the backend...? If you're following step by step, should you not be getting the same thing?
 
Ok so I am going to finally try to turn something into an addon for real and I figured it would be better to come back here and give this example another whirl with new eyes before I did. LOL it was a good call. I am now stuck at this point here..

Addon created, Listener.php created, code event listener created. Everything saves fine...but my link doesn't show up in the footer...what could I possible be doing wrong?

library/Bigfoot/Listener.php
PHP:
<?php

class Bigfoot_Listener
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'footer_links')
        {
            $content .='<li><a href="http://iamnowhere.com">A link to nowhere</a></li>';
        }
    }
}
 
Ok so I am going to finally try to turn something into an addon for real and I figured it would be better to come back here and give this example another whirl with new eyes before I did. LOL it was a good call. I am now stuck at this point here..

Addon created, Listener.php created, code event listener created. Everything saves fine...but my link doesn't show up in the footer...what could I possible be doing wrong?

library/Bigfoot/Listener.php
PHP:
<?php

class Bigfoot_Listener
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'footer_links')
        {
            $content .='<li><a href="http://iamnowhere.com">A link to nowhere</a></li>';
        }
    }
}
At a glance it looks like your variables aren't matching ($contents / $content).
 
At a glance it looks like your variables aren't matching ($contents / $content).

To quote James
Facepalm, thanks <insert Name>
Something about chain reactions makes me laugh...I just spent the whole time reading the thread and wondering what I was missing and this was discussed but when I was following the video my noobass self just decided to ignore the earlier discussion here about if you are copying the callback signature from your CP you wont have a problem. I guess I should have thought about that when listening about modifying inside the function.

Thanks Onimua

it works! on to seeing if I can work something into a real addon :-):-):-)
 
Hi, I am using the 'post_private_controls' hook from the 'post' template.
Since this hook does not have any params, I thought I'd use $template->getParams(), however, this returns the Thread parameters and not the Post ones.
How do I go about retrieving the Post params?
Thanks.
 
it works! on to seeing if I can work something into a real addon :):):)

Update:
First addon ever completed. Go me :) This is one of my favorite threads of all time now. I can't believe I made something that works..I am going to keep testing it but I think I am good (to clarify good in this case where I am from means alright, or OK, or safe.)

Thanks everyone!!!!
 
Just to be sure: the BEST way to edit a style is by making callbacks to template hooks? so, every change should be made this way? using this method my styles will ALWAYS persist when I update my XenForo?

I bought my licence about a month ago, but hadn't tested the software until a few days ago, so maybe I missed some other tutorials that completes the information shown here... I don't know. Please be patient :p

BTW: XenForo is awesome ^^
 
Just to be sure: the BEST way to edit a style is by making callbacks to template hooks? so, every change should be made this way? using this method my styles will ALWAYS persist when I update my XenForo?

I bought my licence about a month ago, but hadn't tested the software until a few days ago, so maybe I missed some other tutorials that completes the information shown here... I don't know. Please be patient :p

BTW: XenForo is awesome ^^
No, template hooks are really for add-ons to modify templates. If you want to customise your style, the template editor is the preferred approach.
 
Thank you Kier ^^
I was complicating everything xP

Anyway, testing this template hook feature I noticed that it's extremely easily to add html at the beginning or at the end of the content (in $contents). But what if I want to add something in the middle? the only way would be to overwrite the data stored in $contents with the same previous data + the changes I made?
 
Thank you Kier ^^
I was complicating everything xP

Anyway, testing this template hook feature I noticed that it's extremely easily to add html at the beginning or at the end of the content (in $contents). But what if I want to add something in the middle? the only way would be to overwrite the data stored in $contents with the same previous data + the changes I made?
That's correct. Some template hooks include 'slots' and 'blocks' that you can use to insert content in the middle of the hook area using string manipulation functions.
 
I would like to add something to account_wrapper, but only on the account_upgrades template.

How can I do that? :s
 
I would like to add something to account_wrapper, but only on the account_upgrades template.

How can I do that? :s

If you catch the hook you want, but then also check the $template->getTemplateName() is what you're after, I think getTemplateName should give you the "master" template name.
 
If you catch the hook you want, but then also check the $template->getTemplateName() is what you're after, I think getTemplateName should give you the "master" template name.

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?
 
Top Bottom