为什么方法addStyleSheet ,,不会在joomla 3.4中将我的css文件添加到我的网页

时间:2016-01-02 10:26:58

标签: javascript html css3 templates joomla3.0

我想通过以下来源将 css js 文件添加到我的模板joomla3.4 : 但是当我运行joomla temp时,在 fire fox view source 网页中,bootrap和js文件在源中不存在而且我的temp没有bootstap和js文件,可以任意帮帮我?

<html>
    <head>
        <meta charset="UTF-8">
        <title>mymagazine</title>
      <?php

defined('_JEXEC') or die;

$app             = JFactory::getApplication();
$doc             = JFactory::getDocument();
$user            = JFactory::getUser();
$this->language  = $doc->language;
$this->direction = $doc->direction;

// Getting params from template
$params = $app->getTemplate(true)->params;

// Detecting Active Variables
$option   = $app->input->getCmd('option', '');
$view     = $app->input->getCmd('view', '');
$layout   = $app->input->getCmd('layout', '');
$task     = $app->input->getCmd('task', '');
$itemid   = $app->input->getCmd('Itemid', '');
$sitename = $app->get('sitename');

if($task == "edit" || $layout == "form" )
{
    $fullWidth = 1;
}
else
{
    $fullWidth = 0;
}

// Add JavaScript Frameworks
JHtml::_('bootstrap.framework');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/template.js');

// Add Stylesheets
$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/bootstrap.min.css');

// Load optional RTL Bootstrap CSS
JHtml::_('bootstrap.loadCss', false, $this->direction);

// Adjusting content width
if ($this->countModules('position-7') && $this->countModules('position-8'))
{
    $span = "span6";
}
elseif ($this->countModules('position-7') && !$this->countModules('position-8'))
{
    $span = "span9";
}
elseif (!$this->countModules('position-7') && $this->countModules('position-8'))
{
    $span = "span9";
}
else
{
    $span = "span12";
}

// Logo file or site title param
if ($this->params->get('logoFile'))
{
    $logo = '<img src="' . JUri::root() . $this->params->get('logoFile') . '" alt="' . $sitename . '" />';
}
elseif ($this->params->get('sitetitle'))
{
    $logo = '<span class="site-title" title="' . $sitename . '">' . htmlspecialchars($this->params->get('sitetitle')) . '</span>';
}
else
{
    $logo = '<span class="site-title" title="' . $sitename . '">' . $sitename . '</span>';
}
?>

我的结果在这里:

<html>
 <head>
        <meta charset="UTF-8">
        <title>mymagazine</title>


    </head>
    <body>
        <div  class="page-header"><h1>web design</h1></div>

            </body>
</html>

2 个答案:

答案 0 :(得分:0)

回复在这里:

http://www.inmotionhosting.com/support/edu/joomla-3/create-template/add-css-and-js

<?php

$doc = JFactory::getDocument();

$doc->addStyleSheet('templates/' . $this->template . '/css/style.css');
$doc->addScript('/templates/' . $this->template . '/js/main.js', 'text/javascript');

?>

尽量不要在您的函数中使用$this->baseurladdStyleSheetaddScript

答案 1 :(得分:0)

我的来源太大,我测试小片段来源它的工作:)

$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/bootstrap.min.css');