Chèn CSS fexternal của module Joomla vào template Joomla

  1. helper.php trong thư mục  chứa module của bạn
    /joomla/modules/mod_your_module/joomla/modules/mod_your_module
  2. Thêm hàm addStyleFiles vào class modYour_ModuleHelper
function addStyleFiles () {
 global $mainframe;
 $filename = 'style.css';// Tên file CSS
 $tplpath = DS.'templates'.DS.$mainframe->getTemplate().DS.'css'.DS;
 $tplurl = '/templates/'.$mainframe->getTemplate().'/css/';
// Đường dẫn tới thư mục template của module
 $modurl = '/modules/mod_your_module/tmpl/'; 

 $cssurl = $tplurl;
 if(!file_exists(JPATH_SITE.$tplpath.$filename)){
 $cssurl = $modurl;
 }
 $cssurl = JURI::base().$cssurl;
 JHTML::stylesheet ($filename, $cssurl);
 ?>
 <script type="text/javascript">
 //<![CDATA[ 
 var links = document.getElementsByTagName ('link');
 var included = false;
 if (links.length) {
 for (var i=0;i<links.length;i++) {
 if (links[i].getAttribute('href').test('style.css')) {
 included = true;
 break;
 }
 }
 }
 if (!included) {
 var script = document.createElement('link');
 script.setAttribute('type', 'text/css');
 script.setAttribute('rel', 'stylesheet');
 script.setAttribute('href', '<?php echo $cssurl.$filename; ?>');
 document.getElementsByTagName("head")[0].appendChild(script);
 }
 //]]>
 </script>
 <?php
 }

  1. Triệu gọi phương thức addStyleFiles trong mod_your_module.php
modYour_ModuleHelper::addStyleFiles();
4. Upload file style.css vào thư mục css của template
/templates/your_template/css


0 nhận xét to "Chèn CSS fexternal của module Joomla vào template Joomla"

Đăng nhận xét

Nhãn

Blog Archive

Blog được thiết kế bởi Phùng Văn Minh