Xenforo Hook

  • Thread starter Thread starter Deleted member 10469
  • Start date Start date
D

Deleted member 10469

Guest
Hello, is it possible with hook system XenForo, do this:

// Place my code here
<xen:hook name="header_logo">
<a href="{$logoLink}">LogoTexte</a>​
</xen:hook>

<xen:hook name="header_logo">
// Place my code here
<a href="{$logoLink}">LogoTexte</a>​
</xen:hook>

<xen:hook name="header_logo">
<a href="{$logoLink}">LogoTexte</a>​
// Place my code here
</xen:hook>

<xen:hook name="header_logo">
<a href="{$logoLink}">LogoTexte</a>​
</xen:hook>
// Place my code here

<xen:hook name="header_logo">
<a href="{$logoLink}">LogoTexte</a>​
</xen:hook>

==>

<xen:hook name="header_logo">
// My remplacement code here
</xen:hook>

And is there something similar but with the id and class ?
example:

<div id="myId" class="myClass">
<!-- ... -->​
</div>
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
switch ($DivId)​
{​
case 'myId':​
{​
// ...​
}​
}​
switch ($DivClass)​
{​
case 'myClass':​
{​
// ...​
}​
}​
}

My goal is to add/delete code into templates without modification.
Thank :)
 
Hello, is it possible with hook system XenForo, do this:

And is there something similar but with the id and class ?
example:

<div id="myId" class="myClass">
<!-- ... -->​
</div>

About id and class => on php, not directly: you will to use regex. On javascript, yes: using jquery. Watch and read the tutorials.... even 5, 6,7 times.
 
Ok thank for explanation.
By counter, why it affects what the administration pannel please?

My code :

PHP:
<?php
 
class XenCrea_Hook_HeaderBanner // NomDossier_NomDossier_NomFichierPhp
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        switch ($hookName)
        {
            case 'xenforo_css_extra'
            {
                $contents .= $template->create('XenCrea_HeaderBanner.css', $template->getParams());
                break;
            }
        }
    }
}

GOOD =>
1bhYl.jpg


BAD =>
1bhYJ.jpg


There is a way not to affect the administration? ^^
 
What is the hook 'xenforo_css_extra' ? I don't think it exists. And the command $template->create doesn't work with css templates.

What you need to do is first create a css template, then create a normal template (same name for example), then put that code inside the normal template:

Code:
<xen:require css="Mytemplate.css" />

Don't forget this code, even if both templates have the same name (in this case the css template will automatically appear with the normal template BUT will not be included.


After this, you can use the command $template->create with the normal template.
 
What is the hook 'xenforo_css_extra' ? I don't think it exists. And the command $template->create doesn't work with css templates.

Hook "xenforo_css_extra" load EXTRA.css template :)

I just tested, I confirm with certainty that $template->create(); work with css :)
 
If you want to have the hooknames per page, add this to your hook listener:

Code:
 if ($hookName == $hookName) { $contents .= '<span style="diplay:inline;color:red;">' . $hookName . '</span><br />'; }

or

Code:
 if ($hookName == $hookName) { Zend_Debug::dump($hookName); }

If you want to have the templates per page, add this to your post render listener:

Code:
if ($templateName == $templateName) { $content .= '<span style="diplay:inline;color:red;">' . $templateName . '</span><br />'; }

or

Code:
if ($templateName == $templateName) { Zend_Debug::dump($templateName); }


If you use a $template->create in a postrender listener, you will need to cache the new template to avoid to use a db query.

To cache a template:
Use the listener create template with this code:

Code:
    public static function Your_Function($templateName, array &$params, XenForo_Template_Abstract $template)
    {
        if ($templateName == 'Xen_Template_Name')
        {
            $template->preloadTemplate('Your_Template');
        }
    }
 
Thank, first code is really practical :)
if ($templateName == $templateName) { $content .= '<span style="diplay:inline;color:red;">' . $templateName . '</span><br />'; }
Not work for me :/
and
if ($templateName == $templateName) { Zend_Debug::dump($templateName); }
Display: http://puu.sh/1biqd.jpg / http://puu.sh/1biqk.jpg

Are you sure???

Yes, I just tested by emptying my cache every time :)
The picture in my header is in my css and I called unmediated :)
 
After some test with that 'hook' (xenforo_css_extra) it appears it breaks the layout if you use it. I guess if it is used in an addon, it prevent the css to load.
 
Thank, first code is really practical :)

Not work for me :/
and

Display: http://puu.sh/1biqd.jpg / http://puu.sh/1biqk.jpg

You didn't see enough times the videos made by Kier ;)
You need to use the template_post_render listener for the second code to work and not use it in the template_hook listener

template_hook => your can play with the hook content BEFORE the template is parsed
template_post_render => you can play with the template content AFTER the template is parsed
tempalte_create => usefull for cache templates (only when needed; for example when use $template->create in template_post_render)
 
Top Bottom