Skip to content

Instantly share code, notes, and snippets.

@atdt
Created June 22, 2012 20:17
Show Gist options
  • Save atdt/2974946 to your computer and use it in GitHub Desktop.
Save atdt/2974946 to your computer and use it in GitHub Desktop.
Conditionally load module and set JS config var
/* declare your module */
$wgResourceModules['ext.Foo'] = array(
'scripts' => array( 'js/ext.Foo.js' ),
'localBasePath' => dirname( __FILE__ ),
'remoteExtPath' => 'MyExtension'
);
/* hook into BeforePageDisplay */
$wgHooks['BeforePageDisplay'][] = 'loadConditionally';
/* load module and set config var if some condition is true */
function loadConditionally( &$out ) {
if ( someCondition() ) {
$out->addJsConfigVars( array (
"wgAnswer" => 42,
"wgServerDate" => getdate();
) );
$out->addModules( 'ext.Foo' );
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment