我想添加这个角度脚本:
<script src="/sitename/templates/templatename/app/modules/form/form.js"></script>
..从Joomla Nooku查看my-account.html.php的head脚本底部。因为在模板文件中有$ doc-&gt; addScript()用于添加类似AngularJS本身的脚本。因此,视图中添加的自定义脚本需要位于底部。
怎么做?
如果我在视图中使用AddScript(),脚本将添加到头部脚本的顶部。
我想出了一个解决方案......好吧。在模板文件中,我指定了我想要移动到头部脚本底部的文件。像这样(欢迎更好的解决方案/方法):
moveScriptToBottom($doc->_scripts, '/sitename/templates/templatename/app/modules/form/form.js');
function moveScriptToBottom(&$scripts, $src)
{
foreach ($scripts as $key => $value) {
if ($key === $src) {
$move = $scripts[$key];
unset($scripts[$key]);
$scripts[$key] = $move;
}
}
}
答案 0 :(得分:1)
这肯定会这样做
<?php
//get the array containing all the script declarations
$document = JFactory::getDocument();
$headData = $document->getHeadData();
$scripts = $headData['scripts'];
//remove or add your script
$scripts['/sitename/templates/templatename/app/modules/form/form.js']
$headData['scripts'] = $scripts;
$document->setHeadData($headData);
?>
您可以通过此
删除一些不需要的脚本 unset($scripts['/media/system/js/mootools-core.js']);
答案 1 :(得分:1)
没有Joomla本地方法可以做到这一点,所以你提出的解决方案或多或少是唯一的方法。
答案 2 :(得分:0)
您可以通过使用“ addCustomTag”来做到这一点,尽管它不能保证将script标签添加到页面的末尾,但仍然可以解决Joomla的许多序列问题。 / p>
$doc->addCustomTag('<script src="' . JURI::root(true) . '/js/yourscript.min.js" type="text/javascript"></script>');