0

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?

1 Answer 1

2

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->.

Sign up to request clarification or add additional context in comments.

11 Comments

I changed jQuery, and module as you suggested, but script from module is still not loading. Does this have something to do with me using addScript from default.php (module layout)?
no, there's nothing wrong with the code. silly question, but are you sure the file is actually there?
Not a silly question - file is there, module is working and I am getting layout, and I did a double check on JS file. I also made newslist.php, to try instead of js file, but it is not working.
do you think you would be able to provide a copy of the module zip?
I am sorry to bother you, but I am kinda stuck, and still without solution - any thoughts about the problem?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.