How To Use Template Hooks

Call me stupid, but I ran into a problem...
What I want to do.. is add a footer A (like in the video) to every page...
that works fine, thx kier..
Now (and here is my problem) i want the footer to show on every page, except on the member page, where I want to show Footer B (A and B are different content)
I was going to do a selection by template name, but that seems not to be possible, because the template name is always: PAGE_CONTAINER
and that one is on all pages...

any ideas? the code would be:

PHP:
if( page is NOT memberpage)

$contents .= $template->create('footerA');

else

$contents .= $template->create('footerB');

its the page id or something like that I am missing...

Thanx for any ideas..

Luc
 
if ($template->getParam('controllerName') == 'XenForo_ControllerPublic_Member' AND $template->getParam('controllerAction') == 'Member')

should work
 
What if I wanted to do something like this (excuse the horrible mockup):

XnXXZ.png


My question is how would I get rid of the current Xen footer so it can be replaced with my custom one, and could I pull the content from the original footer template into mine so that if that original footer content updates my custom footer will still pull its updated contents into the very bottom bar?

Am I explaining this ok? Hope someone understands what I'm getting at here. So far with template hooks all I know how to do is ADD ON to content, but how can I replace content? Perhaps I'm going about this the wrong way... at any rate suggestions and help are greatly appreciated, thanks!
 
Hey.
I think I understand your problem.
But in my opinion this is a buyable thing.
You can buy the extra "Branding removal" which costs 250 $, this should solve your problem, right?
Otherwise I don´t think that you are allowed to remove XenForo from the footer.
From technical view can you solve this with a new footer
The footer is just a file, which contains the creates for html.
But before I do this, I would ask Kier for the licensing theme.

Faithfully
 
Why not just attach the XF footer to the bottom of your site? You can remove the default footer by editing the footer template.
 
Why not just attach the XF footer to the bottom of your site? You can remove the default footer by editing the footer template.
I'll probably end up doing just this, simple enough and works.

template hook "footer" => $contents = ''; "deletes" everything from the footer template ;)

BUT wouldn't it be possible to change most things via css?
Thanks for the tip. And I'm not entirely sure about the CSS, I'm doing a template hook with a custom footer template because I'm going to change the structure around and add some divs for the custom content, I figured this would be the way to go. :confused:
 
Ok this just doesn't work for me. Code is:

<?php

class EnvolveChat_Listener
{
public static function templateHook($hookName, &$content, array $hookParams, XenForo_Template_Abstract $template)
{
$content .= '<li>aeoe</li> <br> <span>aeoe asdf dfs d sfaf</span>';
}
}

Help me please. I'm looking into these 2 rows for two days already. Is it the code or is there another reason that this function is not called at all? When I write a wrong function name in the Code Event Listeners editor, it gives me error, so I know function name is correct.
 
Ok this just doesn't work for me. Code is:

<?php

class EnvolveChat_Listener
{
public static function templateHook($hookName, &$content, array $hookParams, XenForo_Template_Abstract $template)
{
$content .= '<li>aeoe</li> <br> <span>aeoe asdf dfs d sfaf</span>';
}
}

Help me please. I'm looking into these 2 rows for two days already. Is it the code or is there another reason that this function is not called at all? When I write a wrong function name in the Code Event Listeners editor, it gives me error, so I know function name is correct.
Try:

PHP:
<?php

class EnvolveChat_Listener
{
   public static function templateHook($hookName, &$content, array $hookParams, XenForo_Template_Abstract $template)
{
  if ($hookName == 'some_hook')
  {
      $content .=  '<li>aeoe</li> <br> <span>aeoe asdf dfs d sfaf</span>';
  }
}
}
 
Why do you think that will help? If there's a check the content will be changed for the specified hook only. I removed the check so that the contents should be changed for all hooks, but guess what - it doesn't change for any hook. And yes I already tried with check but logically it still doesn't work.
 
And if you add
PHP:
die('here we are');
into your code?

Does the script stop there?
If not, something's wrong with the code event listener;)

Or try something without "<li>"... because most templates doesn't have a list, so maybe there are only rendering problems and the template hook is working fine;)
 
If you return print_r($content) - does it actually return anything? I was under the impression the $content variable is the contents of the template hook, which leads me to believe you need a hook to render the $content. I'm not sure though.
 
I'm stupid. I've added $config['enableListeners'] = false; in my config.php for the purpose of previous tutorial. That was the problem. Thanks for the hint that it's problem with event listener.
 
Quick question,

Let's use this code for example taken from message:

Code:
        <xen:hook name="message_content" params="{xen:array 'message={$message}'}">
        <div class="messageContent">
            <article>
                <blockquote class="messageText ugc baseHtml{xen:if $message.isIgnored, ' ignored'}">
                    <xen:include template="ad_message_body" />
                    {xen:raw $message.messageHtml}
                </blockquote>
            </article>

            {xen:raw $messageContentAfterTemplate}
        </div>
        </xen:hook>

I know how to add content to the end of hooks, but what if I wanted to add content inside the hook, or just below it, or just above it? Let's say my custom content is "Bananas", would it be possible to get it here:

Rich (BB code):
        <xen:hook name="message_content" params="{xen:array 'message={$message}'}">
         "Bananas"
        <div class="messageContent">
            <article>
                <blockquote class="messageText ugc baseHtml{xen:if $message.isIgnored, ' ignored'}">
                    <xen:include template="ad_message_body" />
                    {xen:raw $message.messageHtml}
                </blockquote>
            </article>

            {xen:raw $messageContentAfterTemplate}
        </div>
        </xen:hook>

or here:

Rich (BB code):
          "Bananas"
        <xen:hook name="message_content" params="{xen:array 'message={$message}'}">
        <div class="messageContent">
            <article>
                <blockquote class="messageText ugc baseHtml{xen:if $message.isIgnored, ' ignored'}">
                    <xen:include template="ad_message_body" />
                    {xen:raw $message.messageHtml}
                </blockquote>
            </article>

            {xen:raw $messageContentAfterTemplate}
        </div>
        </xen:hook>

I don't suppose it's possible? I guess I could always set contents = '' and then my custom content would be that entire snippet inside the hook, but if xen ever updates that... just not the best solution.

While I'm on the subject, what if I wanted to do this:

Rich (BB code):
        <xen:hook name="message_content" params="{xen:array 'message={$message}'}">
        <div class="messageContent">
             "Bananas"
            <article>
                <blockquote class="messageText ugc baseHtml{xen:if $message.isIgnored, ' ignored'}">
                    <xen:include template="ad_message_body" />
                    {xen:raw $message.messageHtml}
                </blockquote>
            </article>

            {xen:raw $messageContentAfterTemplate}
        </div>
        </xen:hook>

same thing as above? would have to replace the contents? I don't know much about templatehooks yet so I'm still looking to learn. If anyone could provide insight on my silly questions I'd greatly appreciate it. Thanks!
 
Before the hook is simple $contents = $yourContent . $content;

Then certain places inside a hook is situational. With your last snippet you can simple use strpos, substr and strlen to manipulate the string.

Then with more complext contents you should be using DOMDocument. However it has some things you need to get around. I am writing a library to make a lot of these things easier, like exending DOMDocument to do encoding right and not add <html><body> stuff when using DOMDocument->saveHTML().
 
Just to help a bit. Here is how you would do that part (just typing this out, i might put in errors).

$pos = strpos($content, '<div class="messageContent">');
$content = substr($content, 0, $pos) . '"Bannanas"' . substr($content, $pos);
 
Oh nice, doing the hard part for me haha, appreciate it man thanks. I'll give it a try and adjust accordingly.

Edit: Here's the final code that worked perfectly for me if anyone needs a reference to do something similar:

PHP:
$pos = strpos($contents, '<div class="messageContent">');
$contents = substr($contents, 0, $pos) . $template->create('plague_message_bar', $template->getParams()) . substr($contents, $pos);

plague_message_bar being the template containing the custom content I wish to put under the messageContent div. Thanks again Robbo :D

Edit 2: Realized I didn't even need to do this, as the placement for my custom template would be wrong when viewing deleted posts (it would appear below the noticies, I wanted it to always be the first thing at the top), instead ended up using:

PHP:
            case 'message_notices';
            {
                $contents = $template->create('plague_message_bar', $template->getParams()) . $contents;
                break;
            }
 
Top Bottom