Reputation: 8705
I am creating custom template and module, and for now it is working, but at the moment I can not load javascript from my module. This is code inside my module:
$doc = JFactory::getDocument();
$doc->addScript(JURI::root() . '/modules/mod_homenewslist/js/newslist.js');
I am guessing that this have something to do with me loading CSS and JS old fashion way (I don't like default Joomla way of loading files into head - to many files). This is my head:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<?php $title = $this->getTitle(); ?>
<title><?php echo $title ?></title>
<link href="templates/pidizajnoptinapirottemplate/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link rel="stylesheet" href="templates/pidizajnoptinapirottemplate/css/reset.css">
<link rel="stylesheet" href="templates/pidizajnoptinapirottemplate/css/template.css">
<script src="templates/pidizajnoptinapirottemplate/js/modernizr-2.6.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.10.2.min.js"><\/script>')</script>
<script src="templates/pidizajnoptinapirottemplate/js/cycle.js"></script>
<script src="templates/pidizajnoptinapirottemplate/js/jfontsize.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="templates/pidizajnoptinapirottemplate/js/main.js"></script>
</head>
What am I doing wrong? If I need to load files Joomla way in order so that module script can be loaded, how can I load only files that I need?
Upvotes: 0
Views: 1283
Reputation: 19743
First of all, you don't need to load jQuery using <script>
tags. This can simply be done using the following which loads it in noConflict mode:
JHtml::_('jquery.framework');
also, as for your module script, try removing the first forward slash "/" before "modules", like so:
$doc->addScript(JURI::root() . 'modules/mod_homenewslist/js/newslist.js');
Update:
Found the issue. Add the following to your template index.php file right below the <head>
tag:
<jdoc:include type="head" />
The gets all scripts, stylesheets and other data that you apply using $doc->
.
Upvotes: 2