Manual:Hooks/SkinAfterPortlet
From Linux Web Expert
SkinAfterPortlet | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> Occurs whenever a page is rendered and allows to add HTML after portlets have been put out. | |
<translate> Define function:</translate> | public static function onSkinAfterPortlet( $skin, $portletName, &$html ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"SkinAfterPortlet": "MediaWiki\\Extension\\MyExtension\\Hooks::onSkinAfterPortlet"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> skins/Skin.php |
<translate> Interface:</translate> | SkinAfterPortletHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:SkinAfterPortlet extensions</tvar>.</translate>
After output of portlets, allow injecting custom HTML after the section. Any uses of the hook need to handle escaping.
Note that if portlet is empty and $html is non empty, the portlet will be rendered.
Details
- $skin Skin
- $portletName: string portlet name
- &$html: string The HTML code to display. Will be wrapped into a div tag, but apart from that will be output into the page directly. Escape dangerous signs!
Example
This example will place an ad in the sidebar following the Toolbox ("tb") portlet. Replace the data-ad-client and data-ad-slot with your own values.
$wgHooks['SkinAfterPortlet'][] = function($skin, $portletName, &$html) { $user = $skin->getUser(); if ($user->isRegistered() && $portletName === "tb") { $html = <<< EOT <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:inline-block;width:160px;height:1000px;margin:20px 0 0 -20px;" data-ad-client="ca-pub-00000000000000" data-ad-slot="000000000"> </ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> EOT; return true; } };