As the title says! I'm trying to figure out if there's a way, within Localsettings.php, to wrap ad tags/scripts with code that indicates they should only execute on pages within the Main namespace. Any suggestions that doesn't require an extension?
Topic on Project:Support desk
You should tell us more details about what code/extension are you using for this. If you're doing the right thing, you'd be using a hook that receives a Title object which you can use to get the namespace of the page.
I am using hooks, but I'm not sure how to get the namespace from that point. We use the SiteNoticeAfter, SkinBuildSidebar, and the SkinAfterContent hooks -- how would I work a check on namespace into that?
Don't use hooks associated with the skin. Use hooks associated with page rendering (see Manual::hooks for details). Then do something like:
if($title->getNamespace == NS_MAIN){
$out->addModules('myscript');
}
maybe try this hook:
Manual:Hooks/BeforePageDisplay
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
if($out->getTitle()->getNamespace() == NS_MAIN){
$out->addModules('mymodule');
}
}
You probably also don't want the module to be loaded for certain actions... so you'll have to make sure to do this only for viewing the article.