Difference between revisions of "How to add some html/js code to pages via hooks"

From aMember Pro Documentation
Jump to: navigation, search
 
Line 1: Line 1:
 
Add this code to [[site.php file]]:
 
Add this code to [[site.php file]]:
 
<source>
 
<source>
Am_Di::getInstance()->hook->add(Am_Event::AFTER_RENDER, 'addTextAbove');
+
Am_Di::getInstance()->hook->add(Am_Event::AFTER_RENDER, function (Am_Event_AfterRender $event) {
 
+
function addTextAbove(Am_Event_AfterRender $event)
+
{
+
 
     if (preg_match('#^/amember/helpdesk/index.*#i', $_SERVER['REQUEST_URI'])) //do it only for specific url
 
     if (preg_match('#^/amember/helpdesk/index.*#i', $_SERVER['REQUEST_URI'])) //do it only for specific url
 
     {
 
     {
 
         $event->replace('#(<h1>Tickets.*</h1>)#i', '$1<div>Some content</div>');
 
         $event->replace('#(<h1>Tickets.*</h1>)#i', '$1<div>Some content</div>');
 
     }
 
     }
}
+
});
 
</source>
 
</source>

Latest revision as of 04:56, 5 February 2016

Add this code to site.php file:

Am_Di::getInstance()->hook->add(Am_Event::AFTER_RENDER, function (Am_Event_AfterRender $event) {
    if (preg_match('#^/amember/helpdesk/index.*#i', $_SERVER['REQUEST_URI'])) //do it only for specific url
    {
        $event->replace('#(<h1>Tickets.*</h1>)#i', '$1<div>Some content</div>');
    }
});