Add code to a template automatically?

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>
 
To the first code you can use the hook login_bar_eauth_set
See:

Rich (BB 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

Rich (BB 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>
 
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 $hookParams, XenForo_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;
        }
    }
}
 
Top Bottom