adib16
adib16

Reputation: 1707

how to add stylesheet and jquery to joomla 3.x module

I create a basic module for joomla 3. this is my file structure .

mod_helloworld.php
mod_helloworld.xml
helper.php
tmpl/default.php
css/style.css
js/javascript.js

this is my source mod_helloworld.php file

<?php 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).'/helper.php' );
?>

now I want to add stylesheet and javascript to this module .I change mod_helloworld.php to this :

<?php 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).'/helper.php' );
$doc =& JFactory::getDocument();
$doc->addStyleSheet( 'css/style.css' );
$doc->addScript('js/javascript.js');
?>

but this not working for me. please help me.

Upvotes: 1

Views: 2736

Answers (1)

Lodder
Lodder

Reputation: 19743

You should use JUir::root() which will automatically define the root of your site for you. So use the following:

$doc = JFactory::getDocument();
$doc->addStyleSheet( JUri::root() . 'modules/mod_helloworld/css/style.css' );
$doc->addScript( JUri::root() . 'modules/mod_helloworld/js/javascript.js' );

Hope this helps

Upvotes: 5

Related Questions