我为 joomla 3 创建了一个基本模块。 这是我的文件结构。
mod_helloworld.php
mod_helloworld.xml
helper.php
tmpl/default.php
css/style.css
js/javascript.js
这是我的源 mod_helloworld.php 文件
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).'/helper.php' );
?>
现在我想向这个模块添加样式表和javascript。我将mod_helloworld.php 更改为 这个:
<?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');
?>
但这对我不起作用。 请帮助我。
最佳答案
您应该使用 JUir::root() ,它会自动为您定义站点的根目录。所以使用以下内容:
$doc = JFactory::getDocument();
$doc->addStyleSheet( JUri::root() . 'modules/mod_helloworld/css/style.css' );
$doc->addScript( JUri::root() . 'modules/mod_helloworld/js/javascript.js' );
希望对你有帮助
关于javascript - 如何将样式表和 jquery 添加到 joomla 3.x 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20606873/