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

Add code to a template automatically?

Discussion in 'XenForo Development Discussions' started by Claudio, Dec 6, 2011.

  1. Claudio

    Claudio Well-Known Member

    I´m trying to insert a piece of code after a certain part of code in the login_bar_form template...
    Could be possible?

    For example, insert a code after this:
    Code:
    <xen:if is="{$xenOptions.facebookAppId}"><xen:set var="$eAuth">1</xen:set></xen:if>
    and this:
    Code:
    <xen:if is="{$xenOptions.facebookAppId}">
                          <li><a href="{xen:link register/facebook, '', 'reg=1'}" class="fbLogin"><span>{xen:phrase login_with_facebook}</span></a></li>
                      </xen:if>
     
  2. Fuhrmann

    Fuhrmann Well-Known Member

    To the first code you can use the hook login_bar_eauth_set
    See:

    Code:
    <xen:hook name="login_bar_eauth_set">
    <xen:if is="{$xenOptions.facebookAppId}"><xen:set var="$eAuth">1</xen:set></xen:if>
    </xen:hook>
    To the second use the hook login_bar_eauth_items

    Code:
    <xen:hook name="login_bar_eauth_items">
    <xen:if is="{$xenOptions.facebookAppId}">
    <xen:require css="facebook.css" />
    <li><a href="{xen:link register/facebook, '', 'reg=1'}" class="fbLogin" tabindex="110"><span>{xen:phrase login_with_facebook}</span></a></li>
    </xen:if>
     
  3. Claudio

    Claudio Well-Known Member

    Emmm where I have to write that? o_O
     
  4. Fuhrmann

    Fuhrmann Well-Known Member

    Create a new code event listener that listen to the template_hook code event.


    PHP:
    class MyHooks_Listener
    {
        public static function 
    templateHook ($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            switch (
    $hookName)
            {
                case 
    'login_bar_eauth_set':   
                    
    //insert the content
                    
    $contents .= "my_content";
                    break;
                case 
    'login_bar_eauth_items':
                    
    //insert the content
                    
    $contents .= "my_content";
                    break;
            }
        }
    }
     
  5. Floris

    Floris Guest

    You will also need a code event listener.
     

Share This Page