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

Xenforo Hook

Discussion in 'XenForo Development Discussions' started by Zephyr, Oct 3, 2012.

  1. Zephyr

    Zephyr Well-Known Member

    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>

    My goal is to add/delete code into templates without modification.
    Thank :)
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. cclaerhout

    cclaerhout Well-Known Member

    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.
     
  4. Zephyr

    Zephyr Well-Known Member

    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 $hookParamsXenForo_Template_Abstract $template)
        {
            switch (
    $hookName)
            {
                case 
    'xenforo_css_extra'
                
    {
                    
    $contents .= $template->create('XenCrea_HeaderBanner.css'$template->getParams());
                    break;
                }
            }
        }
    }
    GOOD =>
    [​IMG]

    BAD =>
    [​IMG]

    There is a way not to affect the administration? ^^
     
  5. cclaerhout

    cclaerhout Well-Known Member

    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.
     
  6. Zephyr

    Zephyr Well-Known Member

    Hook "xenforo_css_extra" load EXTRA.css template :)

    I just tested, I confirm with certainty that $template->create(); work with css :)
     
  7. cclaerhout

    cclaerhout Well-Known Member

    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');
            }
        }
    
     
  8. cclaerhout

    cclaerhout Well-Known Member

    Are you sure???
    I might have made an error a few month ago then.
     
  9. cclaerhout

    cclaerhout Well-Known Member

  10. Zephyr

    Zephyr Well-Known Member

    Thank, first code is really practical :)
    Not work for me :/
    and
    Display: http://puu.sh/1biqd.jpg / http://puu.sh/1biqk.jpg

    Yes, I just tested by emptying my cache every time :)
    The picture in my header is in my css and I called unmediated :)
     
  11. cclaerhout

    cclaerhout Well-Known Member

    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.
     
  12. cclaerhout

    cclaerhout Well-Known Member

    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)
     
  13. cclaerhout

    cclaerhout Well-Known Member

    Yes but all your other css seems to have problems ^^
     

Share This Page