Manual:Hooks/BeforePageDisplay

From MediaWiki.org

Jump to: navigation, search
BeforePageDisplay
Available from version 1.7.0
Allows last minute changes to the output page, e.g. adding of CSS or Javascript by extensions.

*Define function:
function fnMyHook( &$out, &$sk ) { ... }

*Attach hook:
$wgHooks['BeforePageDisplay'][] = 'fnMyHook';
Called from: OutputPage.php

*For more information about attaching hooks, see Manual:Hooks.
*For examples of extensions using this hook, see Category:BeforePageDisplay extensions.


[edit] Details

  • This hook was in SkinTemplate.php until version 1.12.0
  • &$out - The OutputPage object.
  • &$sk - Skin object that will be used to generate the page, added in 1.13.

[edit] Usage

Scripts, styles, and other header elements can be added to the OutputObject at this point. Use:

  • $out->addScript($html) - Add a JS file. $html is a full script tag: '<script type="text/javascript" src="..."></script>'
  • $out->addStyle($src) - Add a CSS file. $src is a URL to a stylesheet.
  • $out->addMeta($name, $value) - Add a <meta> tag.
  • $out->addKeyword($text) - Add a keyword for the keyword <meta> tag.
  • $out->addInlineScript($script) - Add inline JS.
  • $out->addLink($title, $id) - Add a link for the keyword <link> tag.