I am writing a mod for SMF 2.0.x and I want insert a JavaScript file into head.
I see http://www.simplemachines.org/community/index.php?topic=425070.0 but I do not want to modify the source code.
If I use integrate_pre_include/integrate_pre_load it does not work (still there is no variable $context) and I have seen it work with integrate_theme_include/integrate_load_theme
LainaaMyJs.php
function add_js()
{
global $context, $settings;
$context['html_headers'] .= '
<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/MyJs.js?fin20"></script>';
}
I add this to my MOD
$hooks = array(
'integrate_theme_include' => array('$sourcedir/MyJs.php'),
'integrate_load_theme' => array('add_js'),
...
);
if (!empty($context['uninstalling']))
$call = 'remove_integration_function';
else
$call = 'add_integration_function';
foreach ($hooks as $hook => $function)
$call($hook, $function);
Is it correct tp use here integrate_theme_include/integrate_load_theme? Or should I use another hook function?
Yep, the combo integrate_theme_include/integrate_load_theme is find for that kind of things.
As a suggestion, you should use some more "specific" function name. Generic names like add_js are likely to create conflict among mods (for example if two mods were to use a function named add_js it would result in a php error ;)).
I usually use a prefix to name all the functions that belong to a mod.
Thanks!
Lainaus käyttäjältä: emanuele - marraskuu 14, 2013, 09:09:57 AP
As a suggestion, you should use some more "specific" function name. Generic names like add_js are likely to create conflict among mods (for example if two mods were to use a function named add_js it would result in a php error ;)).
I usually use a prefix to name all the functions that belong to a mod.
I also do this (use a sufix in all functions, settings vars and files of a mod), but was only an example ;)
Good! :D
I wrote it just to be sure. ;)