I am getting the error

Fatal error: Call to a member function addStyleSheet() on a non-object in /home/[hidden]/public_html/msa/templates/protostar/index.php on line 187

When I try to view only certain pages on my site. I am using Joomla 3.1.5 and this is my template code:

<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<!-- Include Joomla Header -->
<jdoc:include type="head" />
<!-- Get page title -->
<?php $article = JTable::getInstance("content"); $article->load(JRequest::getInt("id")); $pageTitle = $article->get("title"); ?>
<!-- Open Graph -->
<meta property="og:title" content="<?php echo $pageTitle; ?>"/>
<meta property="og:site_name" content=""/>
<!-- Google Analytics + Webmaster -->
<!-- CSS --->
<link rel="stylesheet" href="/templates/[hidden]/css/responsive-grid.css" media="screen, print, handheld" />
<link rel="stylesheet" href="/templates/[hidden]/css/style.css" media="screen, print, handheld" />
<?php

$document = JFactory::getDocument();
$document->addStyleSheet('templates/[hidden]/style.css');
$document->addStyleSheet(JUri::base().'templates/[hidden]/css/style.css');

JHtml::stylesheet('templates/[hidden]/css/style.css');
?>
有帮助吗?

解决方案

After much deliberation and hunting I found this error was being cause because my template was not set as default. Not sure why it only occurred on some pages but setting the template to default fixed this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top