Created
June 22, 2012 20:17
-
-
Save atdt/2974946 to your computer and use it in GitHub Desktop.
Conditionally load module and set JS config var
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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